我的困境是我想使用
radioGrp.clearCheck();
经过一番研究,我发现这样做的方法就像
selectedid = radioGrp.getCheckedRadioButtonId();
if (selectedid > 0) {
radioGrp.clearCheck();
}
这是因为 getCheckid 可能出现负数或类似的问题。但是,我如何在同一个活动中使用它和以下内容。oncheckedchangedlistener 有它自己的 int id,我认为这会导致问题....
radioGrp.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
.....
我经常收到这个错误
10-04 08:44:03.728: E/AndroidRuntime(420): FATAL EXCEPTION: main
10-04 08:44:03.728: E/AndroidRuntime(420): java.lang.NullPointerException
10-04 08:44:03.728: E/AndroidRuntime(420): at com.mangodeveloper.mcathomie.McatActivityGame$1.onCheckedChanged(McatActivityGame.java:93)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.widget.RadioGroup.check(RadioGroup.java:166)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.widget.RadioGroup.clearCheck(RadioGroup.java:205)
10-04 08:44:03.728: E/AndroidRuntime(420): at com.mangodeveloper.mcathomie.McatActivityGame.fillQuestions(McatActivityGame.java:83)
10-04 08:44:03.728: E/AndroidRuntime(420): at com.mangodeveloper.mcathomie.McatActivityGame.access$8(McatActivityGame.java:51)
10-04 08:44:03.728: E/AndroidRuntime(420): at com.mangodeveloper.mcathomie.McatActivityGame$2.onClick(McatActivityGame.java:128)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.view.View.performClick(View.java:2485)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.view.View$PerformClick.run(View.java:9080)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.os.Handler.handleCallback(Handler.java:587)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.os.Handler.dispatchMessage(Handler.java:92)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.os.Looper.loop(Looper.java:123)
10-04 08:44:03.728: E/AndroidRuntime(420): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-04 08:44:03.728: E/AndroidRuntime(420): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 08:44:03.728: E/AndroidRuntime(420): at java.lang.reflect.Method.invoke(Method.java:507)
10-04 08:44:03.728: E/AndroidRuntime(420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-04 08:44:03.728: E/AndroidRuntime(420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-04 08:44:03.728: E/AndroidRuntime(420): at dalvik.system.NativeStart.main(Native Method)