When developing apps for Android, enter up to 140 words in the text edit box, often showing how many words are left to limit the number of words the user enters.
EditText content;//Define a text input box
TextView hasnum;//used to display the remaining words
int num = maximum number of words 140;//limit
Content = (EditText) Findviewbyid (r.id.et_content);
HASNUMTV = (TextView) Findviewbyid (r.id.tv_num);
Hasnumtv.settext (num+ "");
The following is a EditText text box to add listening
Content.addtextchangedlistener (New Textwatcher () {
Private Charsequence temp;
private int selectionstart;
private int selectionend;
public void beforetextchanged (Charsequence s, int. start, int count, int after) {
}
public void ontextchanged (charsequence s, int start, int before, int count) {
temp = s;
}
public void aftertextchanged (Editable s) {
int number = Num-s.length ();
Hasnumtv.settext ("" + number);
SelectionStart = Content.getselectionstart ();
Selectionend = Content.getselectionend ();
if (temp.length () > num) {
S.delete (SelectionStart-1, selectionend);
int tempselection = Selectionend;
Content.settext (s);
Content.setselection (tempselection);//Set the cursor at the end
}
}
});
TextView input word count and restrictions in Android