I have problem my android app
I have two buttons if i click at the first its work ok,but if i click at the second its do his job and fist job
this is the code:
for the id
rbYes = (RadioButton) findViewById(R.id.rbYes);
rbNo = (RadioButton) findViewById(R.id.rbNo);
for the method
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
switch(buttonView.getId()){
case R.id.rbYes:
flag=true;
etLastHourse.setEnabled(flag);
etLastHourse.setBackgroundColor(Color.WHITE);
etLastGPA.setEnabled(flag);
etLastGPA.setBackgroundColor(Color.WHITE);
Toast.makeText(getApplicationContext(), "OK1", Toast.LENGTH_LONG).show();
break;
case R.id.rbNo:
Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_LONG).show();
flag=false;
etLastHourse.setEnabled(flag);
etLastHourse.setEnabled(flag);
etLastHourse.setBackgroundColor(Color.GRAY);
etLastGPA.setEnabled(flag);
etLastGPA.setBackgroundColor(Color.GRAY);
break;
}
}
for the xml
<RadioButton
android:id="@+id/rbNo"
style="@style/RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="no"
/>
<RadioButton
android:id="@+id/rbYes"
style="@style/RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="yes" />
When you press one button first, you toggle that button only
When you press the other button, you toggle both buttons. Therefore your
onCheckedChangedis checked once the first time you press one of the radiobuttons, and two times the next time.Taken from http://developer.android.com/guide/topics/ui/controls/radiobutton.html
Just do the things you want to if the button is checked.