java - RadioButton - using different formulas -


i've started out , want make program make life easier. i'll count teachers' salary. thing there 2 , 3 month lessons. i've made 2 radiobuttons: 2 month , 3 month:

<radiogroup     android:id="@+id/radiogroup1"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="#ffa24d"     android:orientation="horizontal" >      <radiobutton         android:id="@+id/radio_2m"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_marginleft="24dp"         android:layout_weight="1"         android:text="2 month"         android:checked="false" />      <radiobutton         android:id="@+id/radio_3m"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_marginleft="24dp"         android:layout_weight="1"         android:text="3 month"         android:checked="false" /> </radiogroup> 

i want execute 1 piece code (math formulas , stuff) when 2 month selected , other code (other formulas) when 3 month selected. how do that?

thanks in advance.

do few 'cascading' if statements in code. first, need reference view defined in layout (using findviewbyid(r.id.radio_2m) etc), can use radiobutton.ischecked() tell whether radio button checked.

if(radiobutton1.ischecked()) {     // first radio button checked } else {     // other radio button checked. } 

this works because radiogroup have wrapped both radio buttons in automatically makes sure 1 of child radio buttons checked @ time. should set 1 of radio buttons checked in xml, since default there should 1 selected.