3

我想将 RadioButton 的可见性设置为 INVISIBLE 或 GONE。由于某种原因,这不起作用。

RadioButton myRadioButton = (RadioButton) findViewById(R.id.my_radio_button_id);
myRadioButton.setVisibility(View.GONE);

或者

myRadioButton.setVisibility(View.INVISIBLE);

没有返回错误,它只是不做任何事情。

但是我在 RadioGroup 上试过这个

RadioGroup myRadioGroup = (RadioGroup) findViewById(R.id.radiogroup_quiz_answers);
myRadioGroup.setVisibility(View.INVISIBLE);

它可以很好地隐藏整个组。有没有办法只隐藏一个 RadioButtons?我有一组 3 个是问题的答案,但在某些情况下我想隐藏最后一个。

4

3 回答 3

7

您可以通过这种方式隐藏特定的单选按钮

RadioButton myRadioButton = (RadioButton) findViewById(R.id.last_radio);
myRadioButton.setVisibility(View.INVISIBLE);

或者如果您使用 View Gone menas 单选按钮 hide with sapce

RadioButton myRadioButton = (RadioButton) findViewById(R.id.last_radio);
myRadioButton.setVisibility(View.GONE);

在这种情况下,不要隐藏广播组

RadioGroup myRadioGroup = (RadioGroup) findViewById(R.id.radiogroup_quiz_answers);
myRadioGroup.setVisibility(View.Visible);
于 2013-10-01T05:43:09.653 回答
1

你好,像这样使用。

RadioButton myRadioButton = (RadioButton) findViewById(R.id.my_radio_button_id);
myRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            myRadioButton.setVisibility(View.INVISIBLE);
        }
    });

或者

  <RadioButton
        android:id="@+id/radio0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RadioButton" 
        android:visibility="invisible"/>

这段代码对我有用。希望这会对你有所帮助。

于 2013-10-01T05:40:59.110 回答
0
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final TableLayout bilgiAlani=(TableLayout)findViewById(R.id.bilgiAlani);
    final RadioButton secim1 = (RadioButton) findViewById(R.id.butonSecim1);
    final TextView bilgiMesaji=(TextView)findViewById(R.id.bilgiMesaji);
    secim1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(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 ");
            }
            else if(!secim1.isChecked()) 
            {
                Toast.makeText(getApplicationContext(), "Secmekten Vazgecildi",
                        Toast.LENGTH_SHORT).show();
                bilgiAlani.setVisibility(View.GONE);
                bilgiMesaji.setText("birinci secilmedi");
            }

        }
    });
于 2014-10-25T22:28:15.970 回答