radio button - RadioGroup add RadioButton duplicate when standby phone android -


i have problem radiogroup , add dynamically radiobutton have function:

private void createradio() {         radiogroup rgp= (radiogroup) findviewbyid(r.id.radiogroup);         radiogroup.layoutparams rprms;          for(int i=0;i<radios.length();i++){             radiobutton radiobutton = new radiobutton(this);             try {                 jsonobject object = radios.getjsonobject(i);                 radiobutton.settext(object.getstring("name"));                 radiobutton.setid(object.getint("id"));                 rprms= new radiogroup.layoutparams(radiogroup.layoutparams.wrap_content, radiogroup.layoutparams.wrap_content);                 assert rgp != null;                 rgp.addview(radiobutton, rprms);             } catch (jsonexception e) {                 e.printstacktrace();             }         } } 

where radios jsonarray retrieve db. , problem when put in "stand by" app, , activity stopped when reopen activity found value of radiogroup duplicate. example: if in app have 3 radio button like:
1
2
3

when stanby phone without close app, , reopen app after unlocked phone, find this:
1
2
3
1
2
3

i believe problem rgp.addview add radiobutton without check if radiobutton exists. there method check if radiogroup populated?

you can of following:-

1) remove radiobuttons radiogroup before adding new ones

    radiogroup.removeallviews(); 

2) check if radiogroup populated

    boolean alreadypopulated = radiogroup.getchildcount() > 0; 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -