2

在我的程序中使用带有自定义适配器的微调器。适配器是:

private class lenguageSpinnerAdapter extends BaseAdapter implements
        SpinnerAdapter {

    private ArrayList<String> lenguages;

    public lenguageSpinnerAdapter(Context context,
            ArrayList<String> lenguages) {
        this.lenguages = lenguages;
    }

    public int getCount() {
        return lenguages.size();
    }

    public Object getItem(int position) {
        return lenguages.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            // This a new view we inflate the new layout
            LayoutInflater inflater = (LayoutInflater) context
                    .getApplicationContext().getSystemService(
                            Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.lenguage_item_layout,
                    parent, false);
        }

        TextView lenguage = (TextView) convertView
                .findViewById(R.id.textViewLenguage);
        lenguage.setText(lenguages.get(position).toString());


        return convertView;
    }

}

我在一个活动中使用这个适配器:

ArrayList<String> spinnerArray = new ArrayList<String>();
    spinnerArray.add("IT");
    spinnerArray.add("EN");
    spinnerArray.add("PR");

    final lenguageSpinnerAdapter lenguageAdapter = new lenguageSpinnerAdapter(
            getContext(), spinnerArray);
    spinnerLenguage.setAdapter(lenguageAdapter);

问题是这个微调器总是显示三种语言,但我希望他只显示未选择的语言(如果选择了 IT,则为 EN 和 PR,如果选择了 EN,则为 IT 和 PR)。有任何想法吗?

4

1 回答 1

2
    spinnerLenguage.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int position, long arg3) {

            // Build your new array
            // Build your new adapter
            // Set your new adapter to spinnerLenguage

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });
于 2013-07-16T12:36:06.593 回答