Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText listener for cursor position change

I have a dialog with EditText in it. The EditText is already populated when it is created. When the user places the cursor on or near certain parts of the text a Toast will pop up.

My problem is listening for changes in cursor position. Another post asks the same question and the accepted solution was

You can override onSelectionChanged (int selStart, int selEnd) to get notified about selection changes. If the cursor is moved, this is called as well (in this case selStart == selEnd)

onSelectionChanged (int selStart, int selEnd) is a protected method of the TextView class. How do override it?

like image 552
Mel Avatar asked May 11 '11 09:05

Mel


1 Answers

Just subclass or extend the class EditText and add the following code to the newly create class:

 @Override   protected void onSelectionChanged(int selStart, int selEnd) {         // Do ur task here.     } 

Don't forget to add constructors to the subclass. :)

like image 163
necixy Avatar answered Sep 20 '22 23:09

necixy