android-AutoCompleteTextView不显示下拉菜单,得到警告
作者:互联网
我有一个包含60-70个元素的ArrayList.我将适配器设置为AutoCompleteTextView,如下所示.
AutoCompleteTextView mRecipient = (AutoCompleteTextView) this.findViewById(R.id.recipient);
mRecipient.setThreshold(1);
Log.i("Array list", ""+names);// Here I got the arrayList
ArrayAdapter<String> nameadapter=new ArrayAdapter<String>(MyClass.this, android.R.layout.simple_list_item_1, names);
mRecipient.setAdapter(nameadapter);
但是下拉列表没有显示,并且我在Logcat中得到了一些警告(不是错误).
04-21 17:15:53.017: W/Filter(15093): An exception occured during performFiltering()!
04-21 17:15:53.017: W/Filter(15093): java.lang.NullPointerException
04-21 17:15:53.017: W/Filter(15093): at android.widget.ArrayAdapter$ArrayFilter.performFiltering(ArrayAdapter.java:437)
04-21 17:15:53.017: W/Filter(15093): at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
04-21 17:15:53.017: W/Filter(15093): at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 17:15:53.017: W/Filter(15093): at android.os.Looper.loop(Looper.java:123)
04-21 17:15:53.017: W/Filter(15093): at android.os.HandlerThread.run(HandlerThread.java:60)
我在此下方还有一个ListView,现在为空.
有人能弄清楚这个警告是什么意思吗?
解决方法:
该警告来自ArrayAdapter.performFiltering(CharSequence)中的以下代码片段:
String prefixString = prefix.toString().toLowerCase(); // entered by user
final ArrayList<T> values = mOriginalValues;
final int count = values.size();
final ArrayList<T> newValues = new ArrayList<T>(count); // this will be returned
for (int i = 0; i < count; i++) {
final T value = values.get(i); // in your case, 'value' is null at times
final String valueText = value.toString().toLowerCase(); // the warning
// First match against the whole, non-splitted value
if (valueText.startsWith(prefixString)) {
newValues.add(value);
} else {
final String[] words = valueText.split(" ");
final int wordCount = words.length;
for (int k = 0; k < wordCount; k++) {
if (words[k].startsWith(prefixString)) {
newValues.add(value);
break;
}
}
}
}
因此,请检查名称中的空值.
标签:autocompletetextview,android 来源: https://codeday.me/bug/20191030/1969419.html