android - RadioButton does not switch from "true" to "false" -
i have problem radiobutton declerate in activity_main.xml:
<radiobutton android:id="@+id/radiobutton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/radiobutton00" android:layout_alignbottom="@+id/radiobutton00" android:layout_marginleft="9dp" android:layout_torightof="@+id/radiobutton00" /> <radiobutton android:id="@+id/radiobutton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/radiobutton01" android:layout_alignbottom="@+id/radiobutton01" android:layout_marginleft="7dp" android:layout_torightof="@+id/radiobutton01" />
some of radiobuttons set programaticly "true". user should have right make "false" if clicks on it. @ moment doesn't. if click on it, still true , not switch false.
public class mainactivity extends activity { private radiobutton rb1, rb2; int[][] rbtrue = new int[3][16]; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); rb1 = (radiobutton) findviewbyid(r.id.radiobutton00); rb2 = (radiobutton) findviewbyid(r.id.radiobutton01); } public void setradiobuttons() { steine sander = new steine(); sander.setsteine(); rbtrue = sander.getsteine(); if(rbtrue[0][0] == 1) rb1.setchecked(true); if(rbtrue[0][1] == 1) rb2.setchecked(true); }
so it's pretty easy. gonna give array , check if it's 1 or not. if radiobutton switching true. user need switch false. @ moment it's not possible.
<radiogroup android:id="@+id/radio_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <radiobutton android:id="@+id/radiobutton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="...." android:textsize="15sp" /> <radiobutton android:id="@+id/radiobutton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="....." android:textsize="15sp" /> </radiogroup>
then inside activity,,,
radiogroup rggroup=(radiogroup)findviewbyid(r.id.radio_group); int selectedid = rggroup.getcheckedradiobuttonid(); radiobutton rbtn1 =(radiobutton)findviewbyid(selectedid); toast.maketext(myandroidappactivity.this, rbtn1.gettext(), toast.length_short).show();
Comments
Post a Comment