Populate AutoCompleteTextView with BaseAdapter android

Can someone please give me a link to populate an AutoCompleteTextView using the BaseAdapter in android for phone contacts.

thanks

+4
source share
2 answers

user750716 is invalid. You can populate AutoCompleteTextView with a base adapter. You just need to remember that the BaseAdapter must implement Filterable.

In the Adapter, create an ArrayList of objects. Paste getView with whatever view you want and fill it with the information objects.get (position). Implement getItem (int position) returning a string (name of the object that it clicked on)

In the same adapter add material to filter:

public Filter getFilter() { return new MyFilter(); } private class MyFilter extends Filter { @Override protected FilterResults performFiltering(CharSequence filterString) { // this will be done in different thread // so you could even download this data from internet FilterResults results = new FilterResults(); ArrayList<myObject> allMatching = new ArrayList<myObject>() // find all matching objects here and add // them to allMatching, use filterString. results.values = allMatching; results.count = allMatching.size(); return results; } @Override protected void publishResults(CharSequence constraint, FilterResults results) { objects.clear(); ArrayList<myObject> allMatching = (ArrayList<myObject>) results.values; if (allMatching != null && !allMatching.isEmpty()) { objects = allMatching; } notifyDataSetChanged(); } } 
+11
source

This is not possible in the BaseAdapter, but you can use the CursorAdapter without SQLite DB in the background. In the runQueryOnBackgroundThread function, you can create a MatrixCursor. Something like that:

  String[] tableCols = new String[] { "_id", "keyword" }; MatrixCursor cursor = new MatrixCursor(tableCols); cursor.addRow(new Object[] { 1, "went" }); cursor.addRow(new Object[] { 2, "gone" }); 

I did this in my morphological analyzer.

+1
source

Source: https://habr.com/ru/post/1347906/


All Articles