在我的程序中使用带有自定义适配器的微调器。适配器是:
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)。有任何想法吗?