I would like to make a structure with the condition (if-else) RadioButton
I want that when the Radiobutton RB1 is selected, this function is ac
This worked for me:
Espresso.onView(ViewMatchers.withId(R.id.radiobutton)).check(ViewAssertions.matches(isChecked()))
if(jRadioButton1.isSelected()){
jTextField1.setText("Welcome");
}
else if(jRadioButton2.isSelected()){
jTextField1.setText("Hello");
}
You can also maintain a flag value based on listener,
radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
//handle the boolean flag here.
if(arg1==true)
//Do something
else
//do something else
}
});
Or simply isChecked()
can also be used to check the state of your RadioButton.
Here is a link to a sample,
http://www.mkyong.com/android/android-radio-buttons-example/
And then based on the flag you can execute your function.
Simple Solution
radioSection.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group1, int checkedId1) {
switch (checkedId1) {
case R.id.rbSr://radiobuttonID
//do what you want
break;
case R.id.rbJr://radiobuttonID
//do what you want
break;
}
}
});