Android AutoCompleteTextView 更新
我有一项活动有两个输入:一个用于城市,另一个用于位置。每当用户请求搜索操作时,我都会将城市和位置信息存储在 sqlite 表中。
现在,我希望每当用户输入城市(这是自动建议)时,位置中的自动建议选项应该自动更新。位置和城市的输入小部件都是 AutoCompleteTextView。
这怎么能做到呢?
平均值, 萨潘
I have an activity which has two inputs : one for city and the other for location. I am storing the city and location information in sqlite table whenever the user request a search operation.
Now, i want whenever the user inputs the city(which is a autosuggest), the autosuggest options in location should automatically update. The input widget for location and city are both AutoCompleteTextView.
How can this be done?
Rgds,
Sapan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要向 AutoCompleteTextView 提供一个 CursorAdapter,例如 SimpleCursorAdapter(尽管我尝试时 SimpleCursorAdapter 有问题)。
getCityCursor();
方法应提供通过SQLiteDatabase.query()
获取的游标。更新:我之前提到的“有缺陷的”SimpleCursorAdapter 不是。只需提供一个 CursorToStringConverter 即可。 dan breslau 写了一篇非常好的有关 AutoCompleteTextView 和 SimpleCursorAdapter 的文章位于此处。
you just need to provide a CursorAdapter to the AutoCompleteTextView, e.g. a SimpleCursorAdapter (though the SimpleCursorAdapter was buggy when i tried it).
the
getCityCursor();
method should provide a cursor obtained by aSQLiteDatabase.query()
.update: the "buggy" SimpleCursorAdapter i mentioned earlier isn't. just provide a
CursorToStringConverter
. dan breslau wrote a pretty nice article about AutoCompleteTextView and the SimpleCursorAdapter here.