我为 MultiAutoCompleteTextView 创建了一个自定义适配器,它为我提供了列表视图的视图。问题是,当我输入任何字符时,它会给出正确的计数,但起始索引从 0 开始,因此我看到错误的名称。
String[] personsList = {"Rahul", "Mike", "Mantu","Mathew", "Gatr", "Ahamad"};
AutoCompleteNameAdaptor autoCompleteAdaptor = new AutoCompleteNameAdaptor(getApplicationContext(), personsList);
CustomMultiAutoCompleteTextView personName = (CustomMultiAutoCompleteTextView) findViewById(R.id.allPeopleInvolved);
personName.setThreshold(1);
personName.setAdapter(autoCompleteAdaptor);
personName.setTokenizer(new CustomMultiAutoCompleteTextView.CommaTokenizer());
当列表视图打开时,它总是显示列表项从“Rahul”开始,即使我输入“m”,但计数仍然是 3,所以 3 个项目从项目 0 开始。
这在 android arrayAdaptor 中运行良好,它是:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, personsList);
我是否应该调试以了解为什么它没有在我的适配器的 getView 函数中传递正确的索引,或者我是否需要设置一些排序算法来对列表进行排序并再次在适配器中更新它,如果是的话在哪里?
自定义适配器代码
public class AutoCompleteNameAdaptor extends ArrayAdapter<String> {
LayoutInflater inflater;
String[] listItems;
public AutoCompleteNameAdaptor(Context context, String[] objects) {
super(context, R.layout.people_involved_autocomplete_list, objects);
this.listItems = objects;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
GenericItemViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.people_involved_autocomplete_list, parent, false);
holder = new GenericItemViewHolder();
holder.personNameLabel = (TextView) convertView.findViewById(R.id.personName);
holder.personNameLabel.setText(this.listItems[position]);
convertView.setTag(holder);
} else {
holder = (GenericItemViewHolder)convertView.getTag();
}
return convertView;
}
@Override
public String getItem(int position) {
return this.listItems[position];
}
public static class GenericItemViewHolder {
public TextView personNameLabel;
public ImageView personNameImage;
}
}