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.
source share