AutoCompleteTextView DropDown项setOnItemSelectedListener不起作用

时间:2014-10-16 17:44:06

标签: android autocompletetextview

这是我设置适配器的代码:

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;
    }

}

0 个答案:

没有答案