我已经为AutoCompleteTextView编写了如下代码
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteText);
String[] countries = getResources().getStringArray(R.array.contries_array);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_list_item,countries);
autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
Toast.makeText(getApplicationContext(),"Selected item is :"+item ,Toast.LENGTH_SHORT).show();
}
});
我提供的数组列表是
<string-array name="contries_array">
<item>Afganistan</item>
<item>Canada</item>
<item>India</item>
<item>New Zee Land</item>
<item>New Yourk</item>
<item>Africa</item>
<item>228(BRAZIL_STATION-AIRPORT)</item>
<item>228(AIRPORT-BRAZIL_STATION)</item>
<item>228A(BRAZIL_STATION-LA)</item>
</string-array>
当我搜索“af”或“in”或“22”时,它会正常工作,然后会显示已过滤的列表,但是当我搜索“br”时,我希望它能显示最后三个选项数组已过滤。但它没有显示,它只是在搜索'22'时显示这三个选项。
帮帮我,谢谢你
答案 0 :(得分:0)
ArrayAdapters过滤器的默认实现是搜索单词的开头(以空格分隔)。您需要实现一个使用contains