How to disable automatic opening of a list in AutoCompleteTextView when calling notifyDataSetChanged ()?

Here is my problem:

In my Android application, I use AutoCompleteTextView and update the list of items every 5 seconds. The update works when I call notifyDataSetChanged (). But when I type something here and it will give me a list of matching items, and then I will close it manually when another thread updates the list and the notifyDataSetChanged () drop-down list will be displayed automatically (even if I closed it before). And this is really annoying, because if the list is long, it occupies the entire screen, and after closing it will appear in another 5 seconds. I tried removeDropDown () right after calling notifyDataSetChanged (), but this has no effect. It looks like a drop-down display with a slight delay. This is also a good way to fix this, because if the user has not closed the list, he will be closed after the update. Also tried to focus - still no effect.

Therefore, I need a way: update the list of my elements (via notifyDataSetChanged ()) without automatically displaying a drop-down list, but if the drop-down menu has already been shown, do not close it.

I hope you can help

amuses


I did it finally. I am posting a solution here, maybe someone will use this.

To check if a drop-down menu is visible:

final boolean isVisible = autocomplete.isPopupShowing(); 

Then call notifyDataSetChanged (),

Finally:

 new Handler().post(new Runnable(){ @Override public void run() { if(!isVisible){ autocomplete.dismissDropDown(); } } }); 

This works great.

+4
source share
1 answer

I also have this problem, I think it is a mistake, I solved it as follows.

First of all, set the AutoCompleteTextView auto-detection property to false.

Secondly, change the AutoCompleteTextView auto-detect property to true in the onTouch event of this view. To do this, you need to implement onTouchListener in AutoCompleteTextview.

Whenever you touch this AutoCompleteTextView, you must change the focusable property to true, otherwise keep it focused on false. So that the drop-down list never appears when the view was in an unfocused state.

It displays the drop-down list automatically only when the view is in a focus state, which annoys the user, otherwise it works well.

0
source

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


All Articles