android - How to store the state of the group radio button in a LinearList View -


i have questionnaire in linear layout , radio button group. scroll down linear list , scroll again, selected state of radio button changes default (i.e nothing selected). how can store state of radio button. , heads up, have tried shared preferences method ! doesn't work !! here code :

 class mycustomadapter extends baseadapter {               vector<string> question;               vector<string> answera;               vector<string> answerb;               vector<string> answerc;               vector<string> answerd;                mycustomadapter() {                      question = null;                      answera = null;                      answerb = null;                      answerc = null;                      answerd = null;                }                mycustomadapter(vector<string> qs, vector<string> ansa,vector<string> ansb,vector<string> ansc,vector<string> ansd) {                      question = qs;                      answera = ansa;                      answerb = ansb;                      answerc = ansc;                      answerd = ansd;                      // data_image = image;               }                public int getcount() {                      return question.size();               }                public string getitem(int position) {                      return null;               }                public long getitemid(int position) {                      return position;               }                public view getview(final int position, view convertview,                            viewgroup parent) {                      layoutinflater inflater = getlayoutinflater();                      view row=null;                      row = inflater.inflate(r.layout.accountlist, parent, false);                      textview tv = (textview) row.findviewbyid(r.id.questiontext);                      tv.settext(question.get(position).tostring());                         system.out.println("--------------------------------------");                       rg=(radiogroup)row.findviewbyid(r.id.radio);                      radiobutton rba=(radiobutton)row.findviewbyid(r.id.radioa);                      radiobutton rbb=(radiobutton)row.findviewbyid(r.id.radiob);                      radiobutton rbc=(radiobutton)row.findviewbyid(r.id.radioc);                      radiobutton rbd=(radiobutton)row.findviewbyid(r.id.radiod);                    rba.settext(answera.elementat(position));                      rbb.settext(answerb.elementat(position));                      rbc.settext(answerc.elementat(position));                      rbd.settext(answerd.elementat(position));                         if(position==1){                            rba.setchecked(true);                      }                          rg.setoncheckedchangelistener(new radiogroup.oncheckedchangelistener() {                    @override                    public void oncheckedchanged(radiogroup group, int checkedid) {                        radiobutton rb = (radiobutton) group.findviewbyid(checkedid);                        if(null!=rb && checkedid > -1){  //                         toast.maketext(contestactivity.this, rb.gettext()+""+position, toast.length_short).show();                             system.out.println("*****************************************");                             if(position==0){                                     int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans1=questionid.elementat(position)+":"+id;                             }if(position==1){                                       int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans2=questionid.elementat(position)+":"+id;                             }if(position==2){                                     int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans3=questionid.elementat(position)+":"+id;                             }if(position==3){                                    int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans4=questionid.elementat(position)+":"+id;                             }if(position==4){                                      int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans5=questionid.elementat(position)+":"+id;                             }if(position==5){                                    int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans6=questionid.elementat(position)+":"+id;                             }if(position==6){                                    int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans7=questionid.elementat(position)+":"+id;                             }if(position==7){                                    int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans8=questionid.elementat(position)+":"+id;                             }if(position==8){                                     int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans9=questionid.elementat(position)+":"+id;                             }if(position==9){                                    int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans10=questionid.elementat(position)+":"+id;                             }if(position==10){                                    int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans11=questionid.elementat(position)+":"+id;                             }if(position==11){                                     int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans12=questionid.elementat(position)+":"+id;                             }if(position==12){                                     int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans13=questionid.elementat(position)+":"+id;                             }if(position==13){                                    int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans14=questionid.elementat(position)+":"+id;                             }if(position==14){                                     int index=answervalue.indexof(rb.gettext());                                   string id=answerid.elementat(index);                                   ans15=questionid.elementat(position)+":"+id;                             }                        }                    }                });                    return (row);           } 

you need create 1 array , store state of radio button state.see below code

private boolean[] mychecks = new boolean[question.size()]; private class mycustomadapter extends baseadapter { @override public view getview(final int position, view convertview, viewgroup parent) {     ...     rg.setchecked(mychecks[position]);     rg.setoncheckedchangelistener(new oncheckedchangelistener() {         @override         public void oncheckedchanged(compoundbutton arg0, boolean arg1) {              mychecks[position] = arg1;              /// put code/////         }     }); } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -