HI i have a autocompletextview ,when am typing in autocomplete textview i need to directely query the custom table ,insted put it in array, My custom table contain list of names, how can i do this?
Asked
Active
Viewed 121 times
0
-
you want to retrieve and show each row from database while user typing text or want to get all rows from database and show data from query result without put result in array and use array adapter? – Max Komarychev Mar 14 '11 at 12:05
-
I'm sorry, but I can't still understand: query database WHILE user types text OR show data without putting data into array ? (if second you should use method which is @Sunil Pandey already posted) – Max Komarychev Mar 15 '11 at 10:21
-
when am types in autocompletextview it will directley query the table instead of reading the array – Bytecode Mar 15 '11 at 12:31
1 Answers
0
You should use SimpleCursorAdapter
SQLiteDatabase db // reference to database
// note that your query result should have an id field with name "_id"
Cursor cursor = db.rawQuery("select name_id as _id, name from table_names", new String[]{});
// create adapter over cursor, returned from database
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_dropdown_item_1line, cursor, new String[]{"name"}, new int[]{android.R.id.text1});
AutoCompleteTextView autocomplete = (AutoCompleteTextView)findViewById(R.id.autocomplete_id);
autocomplete.setAdapter(adapter);
Also you should look at SimpleCursorAdapter.CursorToStringConverter
to convert data from cursor to String, which will be displayed. Maybe this link helps you with SimpleCursorAdapter.CursorToStringConverter

Community
- 1
- 1

Max Komarychev
- 2,836
- 1
- 21
- 32