我有这个 Autocomplete 类,我正在修改适配器,以便它不仅会显示文本,还会在出现的文本前显示一个图标。所有可用的选项都存储在字符串数组中。
现在,由于某种原因,无论我输入什么,它都只显示 5 个项目。
public class AutoCompleteText extends Activity{
public class CustomAdapter extends ArrayAdapter<String>{
public CustomAdapter(Context context, int textViewResourceId,String[] objects) {
super(context, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.arow,parent, false);
TextView label = (TextView) row.findViewById(R.id.element);
label.setText(listItems[position]);
ImageView icon = (ImageView) row.findViewById(R.id.image);
if("Item1".equals(listItems[position])|| something else || something else){
icon.setImageResource(R.drawable.img1);
}
else if("Item2".equals(listItems[position])|| something else || something else){
icon.setImageResource(R.drawable.img2);
}
else if("Item3".equals(listItems[position])|| something else || something else){
icon.setImageResource(R.drawable.img3);
}
else if("Item4".equals(listItems[position])|| something else || something else){
icon.setImageResource(R.drawable.img4);
}
else if("Item5".equals(listItems[position])|| something else || something else){
icon.setImageResource(R.drawable.img5);
}
else if("Item6".equals(listItems[position])|| something else || something else) {
icon.setImageResource(R.drawable.img6);
}
else{
icon.setImageResource(R.drawable.whatever);
}
return row;
}
}
AutoCompleteTextView acTextView;
private static String listItems[] = { "Item1", "Item2","Item3","Item4","Item5", "Item6", "Item7", "Item8", "Item9", "Item10"
"Item11", "Item12","Item13","Item14","Item15", "Item16", "Item17", "Item18", "Item19", "Item20");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
acTextView = (AutoCompleteTextView)findViewById(R.id.searchfield);
acTextView.setThreshold(1);
acTextView.setAdapter(new CustomAdapter(AutoCompleteText.this,R.layout.arow, listItems));
acTextView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
try {
//random staff
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
);
}
}
该应用程序编译并运行良好,没有任何错误。谁可以帮我这个事?谢谢你。