我正在创建一个测验应用程序,在其中询问问题并为用户提供选项。对于我使用RadioButton的选项所以我想要的是,一旦用户点击任何一个选项,它就不应该允许任何其他选项点击但问题是它仍然可以点击。如果可能请写代码。谢谢!
# In actualCode.py file
....
....
....
if __name__ == '__main__': # Don't use this condition; it evaluates to false when imported
... # These lines won't be executed when this file is imported,
... # So, keep these lines outside
# Note: The file in your question, as it is, is fine
答案 0 :(得分:1)
点击radiobutton后试试这个:
yourradiobutton.setClickable(false);
yourradiobutton.setClickable(false);
答案 1 :(得分:0)
如果我理解正确,您需要在单击某个RadioButton后禁用RadioGroup。只需添加一个OnCheckedChangedListener,如果单击的RadioButton的id是正确的,则使用setEnabled(false)禁用该组。当然,除非您的代码中有一些其他逻辑可以重新启用,否则您无法重新启用RadioGroup。
RadioGroup radioGroup = (RadioGroup)findViewById (R.id.radioGroup1);
radioGroup.setOnCheckedChangedListener (new OnCheckedChangedListener(){
public void onCheckedChanged(RadioGroup group, int checkedId)
{
if (checkedId == R.id.radio0)
group.setEnabled(false);
}
});
编辑:似乎setEnabled()不起作用,所以你应该尝试更改代码,以便在检查radio0时调用it loops through each RadioButton:
if (checkedId == R.id.radio0){
for(int i = 0; i < group.getChildCount(); i++){
((RadioButton)rg1.getChildAt(i)).setEnabled(false);
}
}
答案 2 :(得分:0)
您可以使用setClickable(false);
。为此:
yourradiobutton.setClickable(false);