【发布时间】:2017-01-04 12:35:09
【问题描述】:
这是我的自定义列表视图类 当我向下滚动我们的列表视图时,它将未选中 privies 选择单选按钮
private String[] question_name;
private String[] op11, op22, op33, op44;
private Activity context;
RadioGroup rg=null;
private HashMap<Integer,String>selectitem=new HashMap<>();
public QustionAdapter(Activity context, String[] queation, String[] op1, String[] op2,
String[] op3, String[] op4) {
super(context, R.layout.qustion_custom_list, queation);
this.context = context;
this.question_name = queation;
this.op11 = op1;
this.op22 = op2;
this.op33 = op3;
this.op44 = op4;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.qustion_custom_list, null, false);
TextView questionname=(TextView)listViewItem.findViewById(R.id.qustion_tb);
RadioButton op1=(RadioButton)listViewItem.findViewById(R.id.op1);
RadioButton op2=(RadioButton)listViewItem.findViewById(R.id.op2);
RadioButton op3=(RadioButton)listViewItem.findViewById(R.id.op3);
RadioButton op4=(RadioButton)listViewItem.findViewById(R.id.op4);
rg=(RadioGroup) listViewItem.findViewById(R.id.radio_group);
// Toast.makeText(context,"Done :"+rg.getCheckedRadioButtonId(),Toast.LENGTH_LONG).show();
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Model model=new Model();
RadioButton rb=(RadioButton) group.findViewById(checkedId);
// Toast.makeText(context,"Done :"+rb.getText(),Toast.LENGTH_LONG).show();
String sel=rb.getText().toString();
selectitem.put(position,sel);
model.setSelectResult(selectitem);
}
});
questionname.setText(question_name[position]);
op1.setText(op11[position]);
op2.setText(op22[position]);
op3.setText(op33[position]);
op4.setText(op44[position]);
return listViewItem;
}'
当我选择第一个单选组按钮时,它会选择,但是当我回到单选组时滚动它时,它会被取消选中。
【问题讨论】:
-
你必须在列表中保存选中或未选中。
-
是的,因为它在滚动后未被选中
-
你应该使用 POJO 类,它将包含问题、选项和检查。更新检查已检查更改侦听器。
-
你能推荐代码吗
标签: android listview radio-group