代码之家  ›  专栏  ›  技术社区  ›  dudi

如何将收音机组视图设置为不可单击

  •  0
  • dudi  · 技术社区  · 6 年前

    我想将我的RadioGroupView设置为不可单击,这样用户就不能单击按钮。我试过了 mRadioGroup.isActivated = false 但这对我的团队观没有影响。有人给我个提示吗?

    5 回复  |  直到 6 年前
        1
  •  4
  •   Prithvi Bhola    6 年前

    为每个按钮禁用

    for (int i = 0; i < mRadioGroup.getChildCount(); i++) {
        mRadioGroup.getChildAt(i).setEnabled(false);
    }
    
        2
  •  2
  •   Ravindra Kushwaha    6 年前

    你试过布景吗 RadioGroupView clickable = false? 如果不起作用,您可以将视图覆盖到整个组布局中,并将此视图设置为“可单击”=true。

        3
  •  2
  •   Deepam Goel Shweta Chauhan    6 年前

    要禁用单选组中的单选按钮,您需要在的帮助下手动禁用每个按钮 radioButton1.setEnabled(false) 方法。 不过,更好的方法是在 getChildAt()

    for (int i = 0; i < mRadioGroup.getChildCount(); i++){
     mRadioGroup.getChildAt(i).setEnabled(false); 
    }
    
        4
  •  1
  •   Markus Penguin    6 年前

    建立在 Prithvi Bhola's answer 您可以使用Kotlin扩展函数,只需将其添加到 Activity :

    fun RadioGroup.setChildrenEnabled(enabled: Boolean) {
        for (i in 0 until childCount) {
           getChildAt(i).isEnabled = enabled
        }
    }
    

    RadioButtons RadioGroup :

    mRadioGroup.setChildrenEnabled(false)
    
        5
  •  0
  •   Faysal Ahmed    6 年前

    试试这个:

    for(int i = 0; i < rg.getChildCount(); i++){
        ((RadioButton)rg.getChildAt(i)).setEnabled(false);
    }
    

    希望这会有帮助。