如何填充AutoCompleteTextView从SQLite数据库高效地一个ListView里面呢? [英] How to populate AutoCompleteTextView inside a ListView from SQLite database efficiently?

查看:141
本文介绍了如何填充AutoCompleteTextView从SQLite数据库高效地一个ListView里面呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从填充我的自定义DataAdaptor ListView控件。我为ListView的每个项目/行定义的布局。这里面的ListView我有一个AutoCompleteTextView。我需要从SQLite数据库的数据绑定。其实这AutoCompleteTextView将列出类别和放大器;这些类别将来自一个SQLite Table.I可以在我里面getView(自定义DatAdapeter类绑定的话),但我不知道如何避免多次调用SQLite数据库?

I am populating the ListView from my Custom DataAdaptor. I have a layout defined for each item/row of the listview. Inside that ListView i have an AutoCompleteTextView. I need to bind it with data from SQLite database. Actually this AutoCompleteTextView will list categories & these categories will come from a SQLite Table.I can bind it in my Custom DatAdapeter class inside getView() but i don't know how to avoid the multiple calls to the SQLite database?

由于类别将保持相同的每一行,所以我想
  类别从数据库和放大器只有一次;与绑定
  AutoCompleteTextView每行中

As the categories will remain the same for each row so i want to get the Categories just once from the database & bind it with AutoCompleteTextView in each row.

有人能指导我该怎么办呢?

Can someone guide me how to do it?

问候。

推荐答案

要避免多个数据库调用。

To avoid multiple database calls ..

您可以从您的活动的的onCreate()然后用的CursorAdapter 或<$ C数据库中获取的游标数据$ C> SimpleCursorAdapter 将其绑定(使用setAdapter)为 AutoCOmpleteTextView 列表中的适配器的 getView() ..

You can fetch data in cursor from database in your activity's onCreate() then using CursorAdapter or SimpleCursorAdapter bind it (using setAdapter) to AutoCOmpleteTextView in your list Adapter's getView()..

这个例子可以帮助你很多使用AutocompleteTextView使用SQLite和CursorAdapter的

This example will help you lot Using AutocompleteTextView with SQLite and CursorAdapter

这篇关于如何填充AutoCompleteTextView从SQLite数据库高效地一个ListView里面呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆