How can I set the focus (and display the keyboard) on my EditText programmatically

后端 未结 13 863
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 02:22

I have a layout which contains some views like this:






&         


        
13条回答
  •  佛祖请我去吃肉
    2020-11-28 02:50

    Try this:

    EditText editText = (EditText) findViewById(R.id.myTextViewId);
    editText.requestFocus();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    

    http://developer.android.com/reference/android/view/View.html#requestFocus()

提交回复
热议问题