如何自定义自动完成textview的建议列表? 我需要在此显示图像和文本,我正在使用baseadapter类,它不能自定义下面是我的代码。请看一下,并给我建议解决这个问题 感谢....
public class AutocompleteTextActivity extends Activity {
/** Called when the activity is first created. */
static final String[] COUNTRIES = new String[] { "Afghanistan", "Albania",
"Algeria", "American Samoa", "Andorra", "India", "Indonesia" };
static final Integer[] Images = { R.drawable.one, R.drawable.two,
R.drawable.three, R.drawable.four, R.drawable.five, R.drawable.six,
R.drawable.seven };
private AutoCompleteTextView searchText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
searchText = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
searchText.setAdapter(new EfficientAdapter(this));
}
private static class EfficientAdapter extends BaseAdapter {
private LayoutInflater li;
public EfficientAdapter(Context context) {
li = LayoutInflater.from(context);
}
public int getCount() {
return COUNTRIES.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = li.inflate(R.layout.listitem, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.text);
holder.image = (ImageView) convertView.findViewById(R.id.image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(COUNTRIES[position]);
holder.image.setBackgroundResource(Images[position]);
return convertView;
}
static class ViewHolder {
TextView name;
ImageView image;
}
}
}