Reputation: 11790
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
.
Upvotes: 1
Views: 788
Reputation: 11790
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);
}
Upvotes: 5
Reputation: 18151
Try
multiEdit.requestFocus();
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Upvotes: 1