這是我的自定義列表視圖類 whem我正在scroling了我們的列表視圖它會選中旱廁選擇單選按鈕無線電集團定製的滾動值會列表視圖適配器選中
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類,它將包含問題,選項並進行檢查。更新檢查選中的更改偵聽器。 –