0
我的自定義適配器微調元件有問題。 Spinner從我的適配器中顯示一個列表,但是當我嘗試選擇項目時它不起作用。Android微調控制器適配器選擇無法使用自定義BaseAdapter
這裏是我的適配器代碼:
public class CategoryAdapter extends BaseAdapter{
private final ArrayList<String> categories;
private Context context;
LayoutInflater inflater;
public CategoryAdapter(Context context, ArrayList catList){
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
categories = catList;
}
@Override
public int getCount() {
return categories.size();
}
@Override
public String getItem(int position) {
return categories.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = inflater.inflate(android.R.layout.simple_spinner_item, null);
}
TextView textView = (TextView) convertView.findViewById(android.R.id.text1);
textView.setTextColor(Color.RED);
textView.setText(getItem(position));
return convertView;
}
}
我在做什麼錯?
define:*但是當我嘗試選擇它不工作*在問題 – Selvin
@Se lvin,當我運行我的應用程序時,微調器沒有選擇任何項目,當我嘗試從微調列表中選擇一個時,不會有任何更改。當我嘗試使用方法spinner.getSelected()時,它返回null。 –
'getSelected()'微調沒有這樣的方法也適配器實現看起來大體上好的...所以問題不在於此代碼... – Selvin