Android editText help
I'm writing an text converter app using an editText. I'va written code in the onTextChange method to replace text in the edittext. But whe开发者_JAVA百科n the replace is done the cursor moves to the begining of the text. I managed to make it go to the end of the text. but thats not what i want. how can i get the last position of the cursor and set it there. using setSelection method. or any other way. help please..
int pos = editText.getSelectionStart();
Selection.setSelection(yourEditText, pos);
There you go. First line saves the position of the cursor in "pos" and second line sets your cursor to it. You can use yourEditText.setSelection(pos) if you prefer for the second line.
This may work:
(mTextView).setText(mData);
int pos = (mTextView).getSelectionStart();
(mTextView).setSelection(mData.length()+pos);
精彩评论