Android: select all text in focus EditField

I am trying to get Android to select all the text in the EditText field when it receives focus. I use this attribute in the layout (in both fields):

        android:selectAllOnFocus="true"

I'm not sure if this is relevant, but to go to the first editable field (the field is also disabled there), I use the following commands:

    quizStartNum.setFocusable(true);
    quizStartNum.requestFocus();

But, when the cursor moves to the desired field, when the layout is first displayed, the text is not highlighted; instead, the cursor ends to the left of the text, by default. If I go to the second field by touching it, all the text will be selected as desired. Then, if I return to the first field by touching it again, the text will also be fully selected. From the very beginning I would like to have behavior. Is there any way to do this?

+3
source share
3

: selectAllOnFocus = "true" , setSelectAllOnFocus (true) EditText.

, SO.

EditText dummy = ... 

dummy.setOnFocusChangedListener(new OnFocusChangedListener(){
    public void onFocusChange(View v, boolean hasFocus){
        if (hasFocus) && (isDummyText())
            ((EditText)v).selectAll();
    }
});
+3

. , Android ?

0

.

, EditText ( " " ), XML- Android hint ().

0

All Articles