以下是我正在使用的适配器。
当我设置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) {
}
};
}
答案 0 :(得分:3)
试试这个
holder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
}
});
这适合我。