2
在我的程序中使用帶有自定義適配器的微調控制器。該適配器:使用自定義適配器的微調器顯示所選項目Android
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);
的問題是,這種微調節目總是三個lenguages,但我想他只顯示未選擇語言(如果選擇了IT,EN和PR;如果選擇了EN,則選擇IT和PR)。有任何想法嗎?
好,非常感謝 – hasmet