Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the selection in an EditText?

How do you programmatically remove the selection from an EditText? I've tried:

myEditText.setSelection(selectionEnd);

but that just creates a selection of 0 length at the end of the current selection. I've also tried Selection.removeSelection(mySpannable), and it just puts an empty selection at the beginning of the text.

like image 209
yuttadhammo Avatar asked Jul 18 '12 03:07

yuttadhammo


People also ask

How do you delete text messages on an android?

Tap the conversation. Touch and hold the message you want to delete. Optional: To delete multiple messages, touch and hold the first message, then tap more messages. Tap Delete to confirm.

How do you make EditText Uneditable?

In your xml code set focusable="false" , android:clickable="false" and android:cursorVisible="false" and this will make your EditText treat like non editable.


2 Answers

To move selection to top:

edit_text.setSelection(0);

To move selection to bottom:

edit_text.setSelection(edit_text.getText().length());
like image 148
live-love Avatar answered Sep 18 '22 12:09

live-love


Calling myEditText.clearFocus();. I think that's what you need

like image 20
user1417127 Avatar answered Sep 19 '22 12:09

user1417127