can someone please give me an link of filling AutoCompleteTextView using BaseAdapter in android for phone contacts.
Thanks
user750716 is wrong. You can fill AutoCompleteTextView with BaseAdapter. You just need to remember that BaseAdapter has to implement Filterable.
In Adapter create your ArrayList of Objects. Implement getView with whatever View you want and fill it with objects.get(position) info. Implement getItem(int position) returning a string (name of clicked object)
In the same adapter add stuff for filtering:
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();
}
}
This is not possible with an BaseAdapter but you can use a CursorAdapter with no SQLite DB in the background. In the function runQueryOnBackgroundThread you can create an MatrixCursor. Something like this:
String[] tableCols = new String[] { "_id", "keyword" };
MatrixCursor cursor = new MatrixCursor(tableCols);
cursor.addRow(new Object[] { 1, "went" });
cursor.addRow(new Object[] { 2, "gone" });
I have done this in my morphological analyzer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With