1
我是新來的android和我正在開發一個應用程序,將用戶輸入保存到數據庫。但是,由於某些原因,當他按下保存按鈕時,我看不到用戶的數據。你能幫我保存這些代碼的值嗎?無法將用戶輸入保存到Android中的數據庫中
activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Spinner
android:id="@+id/spn_District"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/spn_Province"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/spn_InfoType"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txt_Remarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Cons_IReport.java(構造)
public Cons_iReport(String district, String province, String infoType, String rDateObserved, String rRemarks){
this._district = district;
this._province = province;
this._infoType = infoType;
this._dateObserved = rDateObserved;
this._remarks = rRemarks;
}
DatabaseHandler.java
public void SaveReport(Cons_iReport save){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Constants.REPORT_DISTRICT, save.getDistrict());
values.put(Constants.REPORT_PROVINCE, save.getProvince());
values.put(Constants.REPORT_INFOTYPE, save.getInfoType());
values.put(Constants.REPORT_DATEOBSERVED, save.getDateObserved());
values.put(Constants.REPORT_REMARKS, save.getRemarks());
db.insert(Constants.TABLE_REPORT, null, values);
db.close();
}
MainActivity.java
btn_Save.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String rDistrict = spn_District.getSelectedItem().toString();
String rProvince = spn_Province.getSelectedItem().toString();
String rInfoType = spn_InfoType.getSelectedItem().toString();
String rDateObserved = txt_Date.getText().toString();
String rRemarks = txt_Remarks.getText().toString();
databaseHandler.SaveReport(new Cons_iReport(rDistrict, rProvince, rInfoType, rDateObserved, rRemarks));
Toast.makeText(getApplicationContext(), "SAVED!\n" + rDistrict + "\n" + rProvince + "\n" + rInfoType + "\n" + rDateObserved + "\n" + rRemarks, Toast.LENGTH_SHORT).show();
}
});