如何解决使用BaseAdapter android填充AutoCompleteTextView
| 有人可以给我一个链接,该链接使用android中的BaseAdapter填充AutoCompleteTextView进行电话联系。 谢谢解决方法
user750716错误。
您可以使用BaseAdapter填充AutoCompleteTextView。您只需要记住BaseAdapter必须实现Filterable。
在适配器中,创建对象的ArrayList。
用所需的任何视图实现getView并用objects.get(position)信息填充它。
实现getItem(int position)返回一个字符串(单击对象的名称)
在同一适配器中添加用于过滤的内容:
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();
}
}
,对于BaseAdapter,这是不可能的,但是您可以在没有SQLite DB的情况下使用CursorAdapter。在函数runQueryOnBackgroundThread中,您可以创建一个MatrixCursor。
像这样:
String[] tableCols = new String[] { \"_id\",\"keyword\" };
MatrixCursor cursor = new MatrixCursor(tableCols);
cursor.addRow(new Object[] { 1,\"went\" });
cursor.addRow(new Object[] { 2,\"gone\" });
我已经在形态分析仪中完成了此操作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。