How to populate AutoCompleteTextView inside a ListView from SQLite database efficiently?

谁都会走 提交于 2019-12-24 19:04:56

问题


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?

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?

Regards.


回答1:


To avoid multiple database calls ..

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()..

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



来源:https://stackoverflow.com/questions/9030278/how-to-populate-autocompletetextview-inside-a-listview-from-sqlite-database-effi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!