learner
learner

Reputation: 11790

How to show soft-keyboard when MultiAutoCompleteTextView is focused

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

Answers (2)

learner
learner

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

Hoan Nguyen
Hoan Nguyen

Reputation: 18151

Try

multiEdit.requestFocus();
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);

Upvotes: 1

Related Questions