I have a ListView with an EditText on each row working.
I need to select this text on click the edittext to write numbers without erasing or moving the cursor.
Using selectAllonfocus at first works. However, after scrolling the listview, the EditText got crazy and selection doesn't work correctly.
If I execute selectAll in the listener onFocus, then when a touch is made the contextmenu (select word, select all,etc) is shown instead of the selection.
If someone can help.
Thanks.
What I can say about what I asked is that trying to select all text of the listview edittexts don't work properly. So instead of select the text, I show a dialog where the user selects the number or whatever.
On the getView method of your adapter, get your EditView (in this code, edittxt) and do:
I can't tell what it is that you are trying to do. Perhaps it'd help if you can post some of your relevant source code...
But the fact that it gets crazy when you start scrolling makes me thing you aren't handling the convertView correctly in your adapter getView() method.
I dealt with exactly the same problem by doing the following:
Subclassed EditText
Adapter code
Although it's working pretty well, it's not the code I'm proud of... If somebody knows a prettier solution, please tell me!
Not sure if you are still looking for a solution, but I found a way to do it. Add a focus change listener to the edittext in the getView method of your adapter and select all text when focus is received.
I had set windowSoftInputMode to adjustPan for the activity, although I don't think it has any bearing on this matter.
I have tested this on Android 2.3 and 4 and it works.
If you're having problem after scrolling it's the view recycling that's messing you up. You basically need to set up an array to hold the contents of the EditTexts so when you scroll they don't get messed up. You didn't say what was backing your list, but I've got a list with edittexts contained and here's how I handle it (from a cursor, but you could adapt it for an ArrayAdapter):
Then I have a button outside the array that processes it back into my database like this: