我正在使用包含RadioButton(仅限单一选择)的heterogeneous recyclerview
但我的代码没有给我正确的输出
经过多次点击后,它不会给我检查无线电按钮的状态
public class RadioLayout extends RecyclerView.ViewHolder implements View.OnClickListener {
@Bind(R.id.rd_group)
RadioGroup rdGroup;
@Bind(R.id.radio_question)
RadioButton rdQuestion;
public RadioLayout(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
rdQuestion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(previousPos!=getLayoutPosition()){
list.get(previousPos).isChecked=false;
notifyItemChanged(previousPos);
}
list.get(getLayoutPosition()).isChecked=true;
notifyItemChanged(getLayoutPosition());
previousPos=getLayoutPosition();
}
});
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
final EmployeeRecyclerModel model = list.get(position);
try {
if (holder instanceof RadioLayout) {
final RadioLayout headerHolder = (RadioLayout) holder;
headerHolder.rdQuestion.setText(model.answers);
if(model.isChecked) {
headerHolder.rdQuestion.setChecked(true);
}
else{
headerHolder.rdQuestion.setChecked(false);
}