android广播取消,Android - 如何取消选中片段内的广播组中的单选按钮?

在Android应用开发中,遇到一个问题:如何在Fragment的onResume()方法中取消RadioGroup中所有单选按钮的选中状态。尝试了在onResume()里调用RadioGroup的clearCheck()方法,但未成功。代码示例显示了在点击事件中处理单选按钮的逻辑,但未实现onResume()时的清理功能。解决方案是确保在调用super.onResume()之后再执行清除操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我是Android这个世界的新手,我正在学习制作应用程序,所以我遇到了问题。Android - 如何取消选中片段内的广播组中的单选按钮?

工作我创建了一个片段和内部我有一个包含3个单选按钮

清除所有的单选按钮的片段内目标一个无线电组当用户返回到此屏幕时

问题

我不知道如何实现这一

问题

如何清除单选按钮的所有检查?

步骤完成

我试过如下:

但似乎我不能这样做

代码

这段代码不为我工作(从上面的文章)

protected void onResume()

{

RadioGroup rg=(RadioGroup)findViewById(R.id.RG);

rg.clearCheck();

super.onResume();

}

但我有以下几点:

public class Operations extends Fragment

{

RadioButton surfArea, rad, diam;

RadioGroup radG;

Button openSelect;

public Operations()

{

// Required empty public constructor

}

public static Operations newInstance()

{

return new Operations();

}

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

}

@Override

public View onCreateView(LayoutInflater inflater,

ViewGroup container,

Bundle savedInstanceState)

{

View rootView = inflater.inflate(R.layout.fragment_operations_sphere, container, false);

surfArea = (RadioButton) rootView.findViewById(R.id.RB_surfArea);

rad = (RadioButton) rootView.findViewById(R.id.RB_Rad);

diam = (RadioButton) rootView.findViewById(R.id.RB_Diam);

openSelect = (Button) rootView.findViewById(R.id.btn_open_select);

//This piece is for testing purposes

openSelect.setOnClickListener(new View.OnClickListener()

{

@Override

public void onClick(View v)

{

if (surfArea.isChecked())

{

Intent sa = new Intent(getContext(), OperSphere.class);

startActivity(sa);

}

}

});

return rootView;

}

//Here is where I'm stuck

@Override

public void onResume()

{

super.onResume();

}

}

我感兴趣到位内onResume()代码

在此先感谢

2016-09-26

NAYIR55

+0

看起来更符合逻辑的我先调用super.onResume()让Android框架执行任何它所需的操作,然后运行您的代码。 –

+0

你能详细说明吗? –

+0

super.onResume(); RadioGroup rg =(RadioGroup)findViewById(R.id.RG); rg.clearCheck(); –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值