android – Why is the drop-down list for my AutoCompleteTextView obscured by the keyboard only for certain list widths?-ThrowExceptions

Exception or error:

My app uses an AutoCompleteTextView to display data from a list as part of a search, like so:

enter image description here

I want the search field to be visible, so I added the following to my Fragment:

activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

and sure enough, it works as expected when I touch the search text field:

enter image description here

However, when I begin typing characters into the text field, the drop-down list is obscured by the keyboard UNLESS I set dropDownWidth to 101 dp or less:

enter image description here

For example, when I set it to 102 dp or match_parent, I get the following:

enter image description here

I can scroll the list, but it remains obscured.

I searched for the problem on Stack Overflow, but nothing came up. BTW, I’m running on a Pixel 2 with Android 10 and, interestingly enough, the problem doesn’t occur on an emulated Huawei 8 running API 26.

How to solve:

I submitted the problem to google as a bug and am awaiting a response.

###

I faced this problem some time ago . Bellow is an example (java code – cause it was some time ago )
I used DelayAutoCompleteTextView and I ve made custom adapter

private void setAutocompleteForPatientName(ArrayList patients) {
contactName = (DelayAutoCompleteTextView) findViewById(R.id.nameET);
contactName.setThreshold(1);
contactName.setAdapter(new YourCustomAdapter(this, contacts));
contactName.setLoadingIndicator(
(android.widget.ProgressBar) findViewById(R.id.pb_loading_indicator));
contactName.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView adapterView, View view, int i, long l) {

            DO WHATEVER YOU WANT WITH SELECTION

        }
    });
}

My adapter was implementing Filterable .

Bellow is the DelayAutocomplete

public class DelayAutoCompleteTextView extends AutoCompleteTextView {

private static final int MESSAGE_TEXT_CHANGED = 100;
private static final int DEFAULT_AUTOCOMPLETE_DELAY = 750;

private int mAutoCompleteDelay = DEFAULT_AUTOCOMPLETE_DELAY;
private ProgressBar mLoadingIndicator;

private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        DelayAutoCompleteTextView.super.performFiltering((CharSequence) msg.obj, msg.arg1);
    }
};

public DelayAutoCompleteTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public void setLoadingIndicator(ProgressBar progressBar) {
    mLoadingIndicator = progressBar;
}

public void setAutoCompleteDelay(int autoCompleteDelay) {
    mAutoCompleteDelay = autoCompleteDelay;
}

@Override
protected void performFiltering(CharSequence text, int keyCode) {
    if (mLoadingIndicator != null) {
        mLoadingIndicator.setVisibility(View.VISIBLE);
    }
    mHandler.removeMessages(MESSAGE_TEXT_CHANGED);
    mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_TEXT_CHANGED, text), mAutoCompleteDelay);
}

@Override
public void onFilterComplete(int count) {
    if (mLoadingIndicator != null) {
        mLoadingIndicator.setVisibility(View.GONE);
    }
    super.onFilterComplete(count);
}

}

and here is the xml

                <YOURPACKAGE THAT CONTAINS YOUR CUSTOM VIEW CLASS .DelayAutoCompleteTextView
                    android:id="@+id/nameET"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:hint="@string/patientName"
                    android:imeOptions="flagNoExtractUi|actionSearch"
                    android:inputType="textCapSentences"
                    android:paddingRight="20dp"
                    android:textSize="12sp" />

                <ProgressBar
                    android:id="@+id/pb_loading_indicator"

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical|right"
                    android:layout_marginRight="20dp"
                    android:visibility="gone" />
            </FrameLayout>

###

In the meantime, I worked around the problem by moving my AutoCompleteTextView to above the list:

enter image description here

Now the list displays just fine:

enter image description here

I think the problem was due to the AutoCompleteTextView being at the bottom of the page.

Leave a Reply

Your email address will not be published. Required fields are marked *