EditText request focus not working

后端 未结 11 657
自闭症患者
自闭症患者 2020-12-15 17:03

I have an EditText and a Button. On click of the button i want to open the EditText keyboard and at the same time request focus on the

11条回答
  •  旧时难觅i
    2020-12-15 17:33

    ensure that the edittext is focusable in touch mode. You can do it two way.

    In xml:

    android:focusableInTouchMode="true"
    

    in Java:

    view.setFocusableInTouchMode(true);
    

    Personally I don't trust the XML definition of this param. I always request focus by these two lines of code:

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    

    The keyboard shoul appear on itself without the need to call InputMethodManager.

    It works in most of the cases. Once it did not work for me because I have lost the reference to the object due to quite heavy processing - ensure that this is not your issue.

提交回复
热议问题