这是我设置适配器的代码:
autoAdapter = new AutoCompleteRouteAdapter(getApplicationContext(),
R.layout.autocomplete_route_item, allRouteList);
acTextView.setAdapter(autoAdapter);
acTextView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Log.i("item","selected");
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
这是我的适配器:
public class AutoCompleteRouteAdapter extends ArrayAdapter<String> {
private Context context;
public AutoCompleteRouteAdapter(Context context, int textViewResourceId, ArrayList<String> items) {
super(context, textViewResourceId, items);
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.autocomplete_route_item, null);
}
String routeText = getItem(position);
TextView route = (TextView) view.findViewById(R.id.route);
route.setText(routeText);
return view;
}
}