我有CheckBox
的數據列表。我需要從我的RecyclerView
中選中或取消選中我的複選框。當我嘗試選擇多個複選框時。RecyclerView中的多項選擇
public class AttendanceAdapter extends RecyclerView.Adapter<AttendanceAdapter.MyStudentsViewHolder>{
private LayoutInflater inflater;
private Context contexts;
List<studinformation> data= Collections.emptyList();
public AttendanceAdapter(Context context,List<studinformation> data){
inflater=LayoutInflater.from(context);
this.data=data;
this.contexts=context;
}
@Override
public MyStudentsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= inflater.inflate(R.layout.customrow_students,parent,false);
MyStudentsViewHolder holder=new MyStudentsViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(MyStudentsViewHolder holder, int position) {
studinformation current=data.get(position);
holder.studentid.setText(current.studID);
holder.studentname.setText(current.studName);
holder.studentid.setSelected(true);
}
@Override
public int getItemCount() {
return data.size();
}
class MyStudentsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CheckBox studentid;
TextView studentname;
public MyStudentsViewHolder(View itemView) {
super(itemView);
studentid= (CheckBox) itemView.findViewById(R.id.ChkSid);
studentname= (TextView) itemView.findViewById(R.id.textName);
studentid.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Toast.makeText(contexts, "Item Clicked At" + getPosition(), Toast.LENGTH_SHORT).show();
if(getPosition()==0) {
// Intent intent = new Intent(contexts, SubActivity.class);
// contexts.startActivity(intent);
}
}
}
}
考慮接受或評論下面的答案。 – Stella