OnCreate Code
hidden_linear = (LinearLayout) view.findViewById(R.id.linear_hidden);
hidden_linear.setVisibility(View.GONE);
rg = (RadioGroup) view.findViewById(R.id.rg);
rg.clearCheck(); //clear any previous checks
rg.check(R.id.radio_no); //default no
OnClick Code
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton radioButton = (RadioButton) view.findViewById(group.getCheckedRadioButtonId());
boolean checked = radioButton.isChecked();
switch (checkedId) {
case R.id.radio_yes:
if (checked && !hidden_linear.isShown())
hidden_linear.setVisibility(View.VISIBLE);
break;
case R.id.radio_no:
if (checked && hidden_linear.isShown())
hidden_linear.setVisibility(View.GONE);
break;
default:
break;
}
}
});
No comments:
Post a Comment