以下是我正在使用的適配器。checkbox.setOnCheckedChangeListener:throw java.lang.reflect.InvocationTargetException
當我設置setOnCheckedChangeListener
時,它拋出異常。
我試圖直接在我的活動中使用setOnCheckedChangeListener
(沒有單獨的適配器),但仍然失敗。
public class InteractiveArrayAdapter extends ArrayAdapter<String>{
private final List<String> list;
private final Activity context;
private final int layOut;
public InteractiveArrayAdapter(Activity context,int rowLayout, List<String> list) {
super(context, rowLayout , list);
this.context = context;
this.list = list;
this.layOut = rowLayout;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(layOut, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.callTitle);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.checkbox);
viewHolder.checkbox
.setOnCheckedChangeListener(checkListener);
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position));
return view;
}
private OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton checkboxView, boolean isChecked) {
}
};
}
一個stacktrace會很好 – Nanne 2011-12-23 16:54:22
thanx ..發現我的錯誤 – WordsWorth 2011-12-23 17:26:35