【发布时间】:2011-05-01 10:21:19
【问题描述】:
如果我第一次设置一个单选按钮,它工作正常。但是如果我通过调用取消选择它 ((RadioButton) findViewById(R.id.ID)).setChecked(false); 然后,稍后即使我尝试通过调用 setChecked(true) 将其选中,除非用户从屏幕中选择它,否则它也将不起作用。
有人遇到过这个吗?还是只有我一个人?
if(Val != null){
if( ((RadioButton) findViewById(R.id.ID1)).getText().toString().trim().equals(Val))
((RadioButton) findViewById(R.id.ID1)).setChecked(true);
else if(((RadioButton) findViewById(R.id.ID2)).getText().toString().trim().equals(Val))
((RadioButton) findViewById(R.id.ID2)).setChecked(true);
}
else {
((RadioButton) findViewById(R.id.ID1)).setChecked(false);
((RadioButton) findViewById(R.id.ID2)).setChecked(false);
}
如果 else 部分至少执行一次,那么一切都会变得一团糟。 当我通过调试器时,我可以看到执行以正确的路径进行并将其设置为 true。它只执行一次,我检查过。而且我不会在代码的任何其他部分将其重置为 false。
【问题讨论】:
-
我们可以看看你的源代码吗?
-
经过groups.google.com/group/android-developers/browse_thread/thread/… 之后,我尝试了这个 android:saveEnabled="false",但这对我没有帮助。哇,至少我并不孤单……
-
有同样的问题,虽然我的布局是图像 - 文本 - 检查图像 - 文本 - 检查我不能只制作一个 RadioGroup ...我发现它是一个“错误”,而我不能使用 setChecked(false) 设置 Radio android-developer 必须做的事情。感谢您的信息,将尝试...
-
欢迎您。这对你有用吗?
标签: android radio-button