Reputation: 3
I have a requirement where the form has to ask "do you have valid license:" and in radio choice 1)yes 2)no . on selection of yes the fields to fill licenseno. , licensee_name and take license photo should appear and on selection of no these thing should be hidden and it should continue with filling of the rest of the form fields .
Upvotes: 0
Views: 2707
Reputation: 3596
For your concern try like this
Get Radio button like this :
RadioButton rbone = (RadioButton) findViewById(R.id.rone);
RadioButton rbtwo = (RadioButton) findViewById(R.id.rtwo);
Get Radio Group like this
radioGroup = (RadioGroup) dialog.findViewById(R.id.rg);
And then fallow like this
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if (rbone.isChecked() == true) {
view1.setVisibility(View.VISIBLE);
view2.setVisibility(View.GONE);
}else{
view2.setVisibility(View.VISIBLE);
view1.setVisibility(View.GONE);
}
}
});
Upvotes: 1
Reputation: 581
Try to write the child View Like licenseno and name and photo inside one layout and give one id to that layout the programmatically you can hide visibility of that block.
Like :
LinearLayout ly=(LinearLayout)findViewById(R.id.LayoutID);
ly.setVisibility(View.INVISIBLE);
OR
ly.setVisibility(View.GONE);
According to Your Radio Button Click Event you can achieve this
Upvotes: 1
Reputation: 2664
Try this.. If your radio buttons belongs to the same group
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId == R.id.radioYes){
view.setVisibility(View.VISIBLE);
}else if(checkedId == R.id.radioNo){
// Depends of your requirement
view.setVisibility(View.INVISIBLE);
// or
view.setVisibility(View.GONE);
}
}
});
Upvotes: 0
Reputation: 225
You can set view.VISIBLE and view.INVISIBLE for controls to visible and invisible
Upvotes: 0