我正在开发一个应用程序,在这个应用程序中我正在使用AutoCompleteTextView,并且面临的问题不多。请查找以下问题的详细情况。
数据中有以下值:
1) Manish Logan Jain
2) M.J. (Logan Fern)
3)洛根
问题:
1)当用户搜索Manish时,Manish Logan Jain显示为建议。但是当用户进入Logan时,就不会返回任何结果。
2)当用户输入Logan时,我希望第二个值显示为建议,但目前,建议列表没有显示任何内容。
3)当用户进入ogan时,我希望能显示建议3。目前,它没有显示。
AutoCompleteView xml:
AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10"
android:hint="@string/enter_user_name" >
<requestFocus />
</AutoCompleteTextView>填充数据的Java代码:
List<String> namesList = new ArrayList<String>(stops);
namesList.add("Manish Logan Jain");
namesList.add("Logan");
namesList.add("M. J. (Logan Fern)");
ArrayAdapter<String> namesSuggestion = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, namesList);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
textView.setAdapter(namesSuggestion);
textView.setThreshold(1);有人遇到过类似的问题吗?如果是,那么解决这一问题的可能办法是什么?
发布于 2014-01-13 09:09:46
对ACTV使用CursorAdapter,对自定义筛选使用setFilterQueryProvider(FilterQueryProvider) (对过滤数据使用MatrixCursor )
编辑:示例FilterQueryProvider
class FQP extends LinkedList<String> implements FilterQueryProvider {
@Override
public Cursor runQuery(CharSequence constraint) {
if (constraint == null) {
return null;
}
Log.d("TAG", "runQuery " + constraint);
String lowerConstraint = constraint.toString().toLowerCase();
String[] columns = {
"_id", "name"
};
int id = 0;
MatrixCursor c = new MatrixCursor(columns);
for (String name : this) {
String lowerName = name.toLowerCase();
if (lowerName.indexOf(lowerConstraint) != -1) {
c.newRow().add(id++).add(name);
}
}
return c;
}
};在onCreate中用以下方法测试它:
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
AutoCompleteTextView actv = new AutoCompleteTextView(this);
String[] from = {"name"};
int[] to = {android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, null, from, to);
FQP fqp = new FQP();
fqp.add("Manish Logan Jain");
fqp.add("Logan");
fqp.add("M. J. (Logan Fern)");
adapter.setFilterQueryProvider(fqp);
actv.setAdapter(adapter);
actv.setThreshold(1);
ll.addView(actv);
setContentView(ll);发布于 2014-01-13 09:02:25
使用实现可过滤的自定义适配器。在getFilter方法中,根据需要使用String.contains()。
请检查这个链接。
发布于 2014-01-13 09:04:12
你要找的是不能直接做的。但我建议你使用MultiCompleteTextView。
参考以下链接:http://www.c-sharpcorner.com/uploadfile/manish1231/autocomplete-and-multicomplete-textview-in-mono-for-android/
https://stackoverflow.com/questions/21087111
复制相似问题