Hiding A Radiobutton In Android
I want to set the visibility of a RadioButton to INVISIBLE or GONE. For some reason this isn't working. RadioButton myRadioButton = (RadioButton) findViewById(R.id.my_radio_button_
Solution 1:
you can hide the particular radio button this way
RadioButtonmyRadioButton= (RadioButton) findViewById(R.id.last_radio);
myRadioButton.setVisibility(View.INVISIBLE);
or if you use View Gone menas radio button hide with sapce
RadioButtonmyRadioButton= (RadioButton) findViewById(R.id.last_radio);
myRadioButton.setVisibility(View.GONE);
In that case do not hide the radio group
RadioGroupmyRadioGroup= (RadioGroup) findViewById(R.id.radiogroup_quiz_answers);
myRadioGroup.setVisibility(View.Visible);
Solution 2:
Hi use like this.
RadioButtonmyRadioButton= (RadioButton) findViewById(R.id.my_radio_button_id);
myRadioButton.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View arg0) {
// TODO Auto-generated method stub
myRadioButton.setVisibility(View.INVISIBLE);
}
});
OR
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton"
android:visibility="invisible"/>
This code is working for me.Hope this will help you.
Solution 3:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TableLayout bilgiAlani=(TableLayout)findViewById(R.id.bilgiAlani);
finalRadioButtonsecim1= (RadioButton) findViewById(R.id.butonSecim1);
final TextView bilgiMesaji=(TextView)findViewById(R.id.bilgiMesaji);
secim1.setOnCheckedChangeListener(newOnCheckedChangeListener() {
@OverridepublicvoidonCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (secim1.isChecked()) {
Toast.makeText(getApplicationContext(), "secildi",
Toast.LENGTH_SHORT).show();
bilgiAlani.setVisibility(View.VISIBLE);
bilgiMesaji.setText("birinci seicmbirinci seicmbirinci seicmbirinci seicmbirinci\n seicmbirinci seicm" +
"birinci seicmbirinci seicmbirinci seicmbirinci seicm" +
"birinci seicmbirinci seicm ");
}
elseif(!secim1.isChecked())
{
Toast.makeText(getApplicationContext(), "Secmekten Vazgecildi",
Toast.LENGTH_SHORT).show();
bilgiAlani.setVisibility(View.GONE);
bilgiMesaji.setText("birinci secilmedi");
}
}
});
Post a Comment for "Hiding A Radiobutton In Android"