有什么简单的方法可以将 2 TextView 下拉菜单设置为 AutoCompleteTextView。
我android.R.layout.two_line_list_item
找不到任何如何使用的示例。
所以,我尝试了这个:
public class TwoLineDropdownAdapter extends BaseAdapter {
private LayoutInflater mInflater = null;
private Activity activity;
public ArrayList<TwoLineDropDown> values = new ArrayList<TwoLineDropDown>();
public TwoLineDropdownAdapter(Activity a, ArrayList<TwoLineDropDown> items) {
values = items;
activity = a;
mInflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return values.size();
}
public TwoLineDropDown getItem(int position) {
return values.get(position);
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView title;
public TextView description;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.dropdown_text_twoline,
parent, false);
holder.title = (TextView) convertView
.findViewById(R.id.text1);
holder.description = (TextView) convertView
.findViewById(R.id.text2);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
public void add(TwoLineDropDown ei) {
values.add(ei);
}
}
但我在这里遇到一个问题:
TwoLineDropdownAdapter AutoCompleteAdapter = new TwoLineDropdownAdapter(this, items);
myAutoComplete.setAdapter(AutoCompleteAdapter);
在设置适配器时它说:
绑定不匹配:AutoCompleteTextView 类型的通用方法 setAdapter(T) 不适用于参数 (TwoLineDropdownAdapter)。推断的类型 TwoLineDropdownAdapter 不是有界参数的有效替代品
如何解决这个问题?
谢谢你