Keyboard hides dropdown menu AutoCompleteTextView

I have AppCompatAutoCompleteTextViewdown below DialogFragment.

On a tablet (API 19) in landscape mode, the drop-down menu is covered with the keyboard when there is only one item in the list of offers. When there are more items, the drop down menu goes up and works great.

There is no problem in a mobile phone (API 22) even if there is only one item in the offer list, the drop-down menu always appears up.

I have already added android:windowSoftInputMode="adjustPan|stateHidden"to the activity in the manifest.

How can I make the dropdown menu always go up or not close with the keyboard?

+4
source share
2 answers
Work around the below the completionThreshold. Hope it works for you!
<AutoCompleteTextView 
  android:id="@+id/someID" 
  android:layout_width="200dp"
  android:layout_height="wrap_content"
  android:completionThreshold="1" />

or

autocomplete.setThreshold(2); 
0
source
  public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager =
            (InputMethodManager) activity.getSystemService(
                    Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(
            activity.getCurrentFocus().getWindowToken(), 0);
}

public void setupUI(View view) {

    // Set up touch listener for non-text box views to hide keyboard.
    if (!(view instanceof EditText)) {
        view.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                hideSoftKeyboard(getActivity());
                return false;
            }
        });
    }

    //If a layout container, iterate over children and seed recursion.
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            View innerView = ((ViewGroup) view).getChildAt(i);
            setupUI(innerView);
        }
    }
}

oncreate setupUI(rootView.findViewById(R.id.parent));

0

Source: https://habr.com/ru/post/1663217/


All Articles