Search code examples
javaandroidkeyboardviewflipper

How can I bring the keyboard into front automatically on a viewflipper?


I have an activity with many viewflippers and want to bring the keyboard of an edittext into front automatically. When I start the activity it works once, logically. With this:

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

or this in manifest:

  <activity
        android:windowSoftInputMode="stateVisible|adjustResize">

So how can I get this when activity is already started and get back to the viewflipper with the edittext?


Solution

  • Try this

    Call this method when you want to show keyboard

    public void showSoftKeyboard() {
            try {
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
                inputMethodManager.toggleSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.SHOW_FORCED, 0);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }