0
我有一個無線電組與兩個單選按鈕(自我交付和公司交付)。在用戶選擇任何一個單選按鈕的應用程序表單。我正在獲取單選按鈕的文本,並通過使用此代碼插入到數據庫中。如何在android中更新時檢查複選框?
Form.java
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
selectedId = radioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioButton = (RadioButton) findViewById(selectedId);
if(radioButton.isChecked()){
OPTIONS=radioButton.getText().toString();
if(OPTIONS.equals("SelfDelivery")){
deliveryAddress.setVisibility(View.GONE);
deliveryEdit.setVisibility(View.GONE);
}else{
deliveryAddress.setVisibility(View.VISIBLE);
deliveryEdit.setVisibility(View.VISIBLE);
}
}
}
});
而用戶想編輯我創造了新的編輯屏幕,並使用代碼更新details.by形式。
EditForm.java
final String ram=extras.getString(openHelper_ob.DELIVERY_OPTIONS);// getting the option from Form.java to EditForm.java
OPTIONS=ram;
if(OPTIONS.equals("CompanyDelivery")){
radioButtonCompany.setChecked(true);
deliveryText.setVisibility(View.VISIBLE);
editAddress.setVisibility(View.VISIBLE);
}else if(OPTIONS.equals("SelfDelivery")){
radioButtonSelf.setChecked(true);
deliveryText.setVisibility(View.GONE);
editAddress.setVisibility(View.GONE);
}
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
selectedId = radioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioButton = (RadioButton) findViewById(selectedId);
if(radioButton.isChecked()){
OPTIONS=radioButton.getText().toString();
if(OPTIONS.equals("SelfDelivery")){
deliveryText.setVisibility(View.GONE);
editAddress.setVisibility(View.GONE);
}else{
deliveryText.setVisibility(View.VISIBLE);
editAddress.setVisibility(View.VISIBLE);
}
}
}
});
我想要做的單選按鈕真正根據用戶的選擇,而回歸到編輯頁面。 例如:如果用戶選擇了公司交貨,當用戶要在交貨選項中編輯表單時,應該在編輯頁面中檢查公司交貨。
我在
radioButtonCompany.setChecked(真)得到錯誤;
的錯誤是
10-10 04:41:20.721: E/AndroidRuntime(794): FATAL EXCEPTION: main
10-10 04:41:20.721: E/AndroidRuntime(794): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android/com.example.android.EditBookingForm}: java.lang.NullPointerException
10-10 04:41:20.721: E/AndroidRuntime(794): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-10 04:41:20.721: E/AndroidRuntime(794): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-10 04:41:20.721: E/AndroidRuntime(794): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-10 04:41:20.721: E/AndroidRuntime(794): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-10 04:41:20.721: E/AndroidRuntime(794): at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 04:41:20.721: E/AndroidRuntime(794): at android.os.Looper.loop(Looper.java:137)
10-10 04:41:20.721: E/AndroidRuntime(794): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-10 04:41:20.721: E/AndroidRuntime(794): at java.lang.reflect.Method.invokeNative(Native Method)
10-10 04:41:20.721: E/AndroidRuntime(794): at java.lang.reflect.Method.invoke(Method.java:511)
10-10 04:41:20.721: E/AndroidRuntime(794): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-10 04:41:20.721: E/AndroidRuntime(794): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-10 04:41:20.721: E/AndroidRuntime(794): at dalvik.system.NativeStart.main(Native Method)
10-10 04:41:20.721: E/AndroidRuntime(794): Caused by: java.lang.NullPointerException