What code do I need to write to have my listener call out the checked Radio Button? Here's my code:
public class TabFragment1 extends Fragment {
RadioGroup radioGroup;
RadioButton radioButtonJa, radioButtonNee;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
radioGroup = (RadioGroup)v.findViewById(R.id.radioGroup);
radioButtonJa = (RadioButton)v.findViewById(R.id.radio_hoogteverschillen_ja);
radioButtonJa.setChecked(true);
radioButtonNee = (RadioButton)v.findViewById(R.id.radio_hoogteverschillen_nee);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup radioGroup, int checkedId)
{
boolean isChecked1 = radioButtonJa.isChecked();
boolean isChecked2 = radioButtonNee.isChecked();
if (isChecked1){
radioButtonJa.setChecked(true);
Toast.makeText(getActivity().getBaseContext(), "Ja", Toast.LENGTH_SHORT).show();
}
else if (isChecked2){
radioButtonNee.setChecked(true);
Toast.makeText(getActivity().getBaseContext(), "Nee", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getActivity().getBaseContext(), "Geen", Toast.LENGTH_SHORT).show();
}
}
});
}
}
When starting my app, it should create a toast but it doesn't. It only creates one when I first click on the other Radio Button. This was also the case with android:checked(true) in the layout file (instead of radioButtonJa.setChecked(true);). How can I get the toast to appear when I open my application?