Search code examples
androidfocusandroid-edittext

Select EditText programmatically in Android


I'm new in Android and I can't select an EditText programmatically. My scenario. I have a lot of EditText, but only one is enable, I'll calling it A. The user write in this EditText A with the keyboard; when he finishes writing, starts an algorithm that recognize the text inside A and put it in the right EditText, for example B. After this I need to empty A and set the focus on it, show the cursor inside A and show the keyboard.

I'll try with myET.requestFocus() but nothing happens.

How can I make A editable again without the user having to touch A ?

Thanks


Solution

  • Try this

    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                myET.requestFocus();
            }
        }, 100);