具有动态适配器更改的 MultiAutoCompleteTextView
我的 Activity 中有一个 MultiAutoCompleteTextView 小部件,其中有一个由基于 Web 的调用的结果填充的 ArrayAdapter
我已经尝试使用 AsyncTask
在后台下载字符串列表,但是 notifyDataSetChanged()
是从“非原始线程”调用的。而且,这似乎有点迂回。
我遇到的另一个选项是可以使用 Filterable
,但我还没有遇到任何简单的示例(AutoComplete4 似乎有点矫枉过正)如何做到这一点。如果没有示例,有人可以对我需要的演员进行广泛的概述 - 过滤器、可过滤器等。
这也是一个好方法吗?
谢谢,
拉贾特
I have a MultiAutoCompleteTextView
widget in my Activity, which has an ArrayAdapter<String>
that is populated by a result from a web-based call. As the user types in characters in the textview, this adapter's list should get updated in the background. What is the best way to implement this?
I have already tried to use AsyncTask
to download the strings list in the background, but notifyDataSetChanged()
was being called from the "non-originating thread". Moreover, this seems a little roundabout.
The other option I came across is that Filterable
can be used, but I haven't come across any simple examples (AutoComplete4 seems like an overkill) on how to do this. If there are no examples, can someone give a broad overview of the actors i will need - Filter, Filterable, etc.
Also is this a good way to go?
Thanks,
Rajath
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这个问题很老了,但我必须做同样的事情,我想我会与你分享解决方案,或者任何人都需要它。
首先,您确实需要使用
AsyncTask
来检索数据。话虽这么说,我永远不会让 AsyncTask 以任何方式操纵我的视图类。相反,我宁愿使用与 AsyncTask 中所需的参数一起传递的回调。 AsyncTask 完成后,您将调用回调方法,该方法将负责调用notifyDataSetChanged()
。这是一些代码:
MyAsyncTask.java
MyCallbackClass.java
I know this question is old, but I had to do the same thing and I figured I'd share the solution with you or anybody would need it.
First of all, you will indeed need to use an
AsyncTask
to retrieve your data. This being said, I'd never let an AsyncTask manipulate in any way my view class. Instead, I'd rather use a callback passed along with the parameters you need in your AsyncTask. As soon as the AsyncTask finishes, you will call your callback method which will be responsible of callingnotifyDataSetChanged()
.Here's some code:
MyAsyncTask.java
MyCallbackClass.java