我有我的适配器类,getView
方法如下:
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.userlist, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text2 = (TextView) view.findViewById(R.id.stuname);
viewHolder.text = (TextView) view.findViewById(R.id.rollno);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.cb);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Model element = (Model) viewHolder.checkbox
.getTag();
element.setSelected(buttonView.isChecked());
// Toast.makeText(getContext(), "Checked",
// Toast.LENGTH_SHORT).show();
}
});
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).getName());
holder.text2.setText(list.get(position).getRoll());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
这里有一个oncheckedchange
听众。
我的问题是如何将诸如哪个列表项更改为我的主要活动之类的信息?此外,当复选框状态发生变化时,我们如何在主要活动中执行一些操作?