Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select all text when clicking on a EditText view?

Tags:

android

so I tried android:selectAllOnFocus and of course I'm using android:hint. The app loads, requestFocus triggers and the full text is selected.

The problem is that when I click in the EditText the selection is lost.

I've already read: Select all text inside EditText when it gets focus

like image 536
Stephan Tual Avatar asked Mar 24 '12 23:03

Stephan Tual


People also ask

How do I get text from EditText view?

We have used getText() method to get the text entered in the EditText views. But getText() method returns an Editable instance and therefore we have typecasted it to convert it into String for further use. This can be done by using the toString() method.

Is EditText a view?

Android App Development for BeginnersA EditText is an overlay over TextView that configures itself to be editable.

How do you make EditText not editable and clickable?

For the above requirement the solution in XML is android:editable="false" but I want to use this in Java. et. setKeyListener(null); It makes the EditText not EDITABLE but at the same time it makes it non clickable as well.


1 Answers

For some reason, it worked (on Jelly Bean) only if I posted it with a Handler:

new Handler().post(new Runnable() {
    @Override
    public void run() {
        paidView.selectAll();
    }
});
like image 182
fhucho Avatar answered Sep 18 '22 06:09

fhucho