android未经检查的单选按钮已经检查过
16lz
2021-01-22
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rg"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.radiogroup.MainActivity" >
<RadioButton
android:id="@+id/rb_true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical" />
<RadioButton
android:id="@+id/rb_false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical" />
</RadioGroup>
i have one radio group in which i have 2 radio button
我有一个广播组,其中我有2个单选按钮
now if radio button 1 is selected and if i tap on same radio button(radio button 1) it should be unchecked ..
现在,如果选择单选按钮1,如果我点击相同的单选按钮(单选按钮1),则应该取消选中它。
it should work astoggle.
它应该工作astoggle。
3 个解决方案
#1
This should serve the purpose.
这应该有助于达到目的。
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup arg0, int id)
{
RadioButton checkedRadioButton = (RadioButton)radioGroup.findViewById(id);
boolean isChecked = checkedRadioButton.isChecked();
if (isChecked)
{
Toast.makeText(getApplicationContext(),
checkedRadioButton.getText(),Toast.LENGTH_LONG).show();
radioButton = (String) checkedRadioButton.getText();
checkedRadioButton.setChecked(false);
}
else
checkedRadioButton.setChecked(true);
}});
Also, don't forget to initialize RadioGroup
另外,不要忘记初始化RadioGroup
更多相关文章
- 在不同状态下使用两个图像切换按钮
- Android Studio 项目的导入以及依赖
- 如何让按钮共享android中对话框宽度的一半?
- 安卓,如何让两个按钮相邻,宽度相同
- 按下子活动后退按钮后,Android主要活动的元素不响应
- 抽象批处理SFTP多目的地和自动重试
- JSP页面中有一个按钮 点击之后执行JAVA文件
- [java混淆器问题] 如何让web项目的class文件不能被反编译,又能在w
- 不幸的是,在声明按钮时,模拟器中出现了错误