I have already tried the usual but it's not working:
multiEdit.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(multiEdit, InputMethodManager.SHOW_IMPLICIT);
Notice my getActivity()
. That's because I am using MultiAutoCompleteTextView
inside a DialogFragment. And the snippet is inside onCreateView
.
The following works for me reliably. It focuses the view automatically. No additional work necessary.
multiEdit.postDelayed(new Runnable() {
@Override
public void run() {
multiEdit.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN, 0, 0, 0));
multiEdit.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
MotionEvent.ACTION_UP, 0, 0, 0));
}
}, 200);
}
Try
multiEdit.requestFocus();
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.