How to Count numbers of line, word and characters from Edittext field in Android

1.3k views Asked by At

I am beginner, I want to make one simple application that will count number of lines, words and characters from whatever we have entered in Editext field. i want result like:

EditText : My name is abc.

Button CLick---->

Result:

No. of Words : 4 No. of Characters : 14 No. of Lines : 1

2

There are 2 answers

0
kiturk3 On BEST ANSWER

lines in edittext can vary depending on device.... for words:

char ch[]= new char[s.length()];      //in string especially we have to mention the () after length
    for(i=0;i<s.length();i++)
    {
        ch[i]= s.charAt(i);
        if( ((i>0)&&(ch[i]!=' ')&&(ch[i-1]==' ')) || ((ch[0]!=' ')&&(i==0)) )
        c++;
    }

and for characters: s.length()

0
sasikumar On

First get the Edittext value.then do like as java word counter

EditText e1=(EditText) findViewById(R.id.youredittextid);
String mytext=e1.getText().toString();

Apply java code for mytext