Moving EditETxt Cursor to the end of spannable text?

1.6k Views Asked by At

I have Edittext where i set spannable text into it and i want the cursor at the end of spannable text . so that user can input manuuly from key board.

i have already tried

ObjectOfEdietext.setSelection(ObjectOfEdietext.getText().lenght());

but it is not working for me. but if i set normal text on the Editext and do the same, it works well. Can anyone point out whats the problem??

thanks in advance

Edited Here i found the problem that LinkMovementMethod which i have set on edit text for making span text clickable, is disabling edittext cursor. Another big problem after i faced is when i set clickable spanned text on edittext then cursor move to 0 postion so i am unable to move cursor at the end of text to add text from keyboard ! has anyone faced such problem before?

2

There are 2 best solutions below

2
On

try this code

ObjectOfEdietext.setSelection(ObjectOfEdietext.getText().toString().lenght());

i have personally tried with following code and its working

et_from.setText(new SpannableString("my starting Address"));
et_from.setSelection(et_from.getText().length());
0
On

Try it, it is working 100%:

yourEditText.post(new Runnable() {
     @Override
     public void run() {
        yourEditText.setSelection(yourBubbleText.length());
     }
});