Swap positions of Radios - Android java -
i got 1 radiogroup 4 radios.
radiogroup rg = (radiogroup) findviewbyid(r.id.radiogroup); radiobutton r0 = (radiobutton) findviewbyid(r.id.radio0); radiobutton r1 = (radiobutton) findviewbyid(r.id.radio1); radiobutton r2 = (radiobutton) findviewbyid(r.id.radio2); radiobutton r3 = (radiobutton) findviewbyid(r.id.radio3);
i set text of them.
r0.settext("1"); r1.settext("2"); r2.settext("3"); r3.settext("4");
so got radios 1, 2, 3, 4. how can randomly swap positions of radios. want 3,2,1,4 or 2,3,1,4....etc... important don't want change text of radios, said want positions swapped.
i don't think can achieve using same layout xml file.
use 4 different layouts, , inflate randomly.
all ids work if keep same in each xml file.
@override public void oncreate(final bundle bundle) { super.oncreate(bundle); setcontentview(randomlayout()); radiogroup rg = (radiogroup) findviewbyid(r.id.radiogroup); // ... } public static int randomlayout() { final int n[] = { r.layout.layout1, r.layout.layout2, r.layout.layout3, r.layout.layout4 } random random = new random(); return n[random.nextint(n.length)]; }
Comments
Post a Comment