如何设置点击监听器单选按钮在安卓监听器、单选、如何设置、按钮

2023-09-12 02:01:50 作者:醉饮千觞不知愁

我有无线电集团内部的两个单选按钮,现在我想设置在点击监听器上的单选按钮。当点击一个单选按钮编辑文本的文本已经改变,当我点击了相同的编辑文本的其他单选按钮文本已更改。

I have two radio button inside the radio group now I want to set On click listener on that radio button. When One radio button is clicked Edit Text text has to change when I click on the Other Radio button text of the same edit Text has changed.

推荐答案

我会想一个更好的办法是使用 RadioGroup中,并设置监听这个变化和更新查看相应地(可以节省您有2或3或4等听众)。

I'd think a better way is to use RadioGroup and set the listener on this to change and update the View accordingly (saves you having 2 or 3 or 4 etc listeners).

    RadioGroup radioGroup = (RadioGroup) findViewById(R.id.yourRadioGroup);        
    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
    {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // checkedId is the RadioButton selected
        }
    });