2

We want to show keypad default when activity starts for AutoCompleteTextView. But AutocompletedTextview is placed in one of the fragment class.When fragement starts default our keypad has be shown.

We tried with three cases:

Case 1:

 getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Case2:

auto_phone.requestFocus();//auto_phone is AutoCompleteTextView
        auto_phone.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((event.getAction() == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_ENTER))) {


                    return sendChatMessage();//method
                }

                return false;
    }

Case 3:

 InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(
                Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(auto_phone, 0);

We used in manifest file also for Activity as Keypad Visible

Please Guide us. Advance Thanks!

1 Answers1

0

This works for me

public static void showSortKeyboard(View focusedView, Activity activity) {
    if (focusedView == null) {
        return;
    }
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(focusedView, InputMethodManager.SHOW_IMPLICIT);
}
Andy
  • 953
  • 1
  • 8
  • 18
  • Thanks for Reponse. But it is not working......... in oncreteView showSortKeyboard(auto_phone,getActivity()); public static void showSortKeyboard(View focusedView, Activity activity) { if (focusedView == null) { return; } InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(focusedView, InputMethodManager.SHOW_IMPLICIT); } – Naresh Kumar Koppera Mar 03 '16 at 06:34
  • We used InputManager in onCreate method imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imgr.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.SHOW_FORCED); – Naresh Kumar Koppera Mar 03 '16 at 06:36
  • You also could try getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); – Andy Mar 03 '16 at 07:07