gpt4 book ai didi

android - 在回收站 View 中只选择一个单选按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:47:56 26 4
gpt4 key购买 nike

我有一个 recyclerview,其中每个项目都有 3 个单选按钮分组在一个单选组中。现在,用户只能在 recyclerview 中为每个项目选择一个单选按钮。但我希望用户在整个回收 View 中只选择一个单选按钮。如何实现?

这是目前的样子。

enter image description here

我想让在整个回收站 View 中只检查 1 个单选按钮成为可能。如果选中第一项中的第一个单选按钮,然后用户单击第二项中的第二个单选按钮,则应取消选中第一项中的第一个单选按钮。

最佳答案

这是另一种方法。这比我之前的回答更优雅。但我保留了两者,因为之前的答案提供了更大的灵 active 。

private RadioButton lastCheckedRB = null;
...
@Override
public void onBindViewHolder(final CoachListViewHolder holder, final int position) {
holder.priceRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton checked_rb = (RadioButton) group.findViewById(checkedId);
if (lastCheckedRB != null) {
lastCheckedRB.setChecked(false);
}
//store the clicked radiobutton
lastCheckedRB = checked_rb;
}
});

关于android - 在回收站 View 中只选择一个单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35218633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com