我是 android 新手,我正在开发一个将用户输入保存到数据库的应用程序。但是,由于某些原因,我看不到用户按下“保存”按钮时所保存的数据。你能帮我保存这些代码中的值吗?
活动.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;
}
数据库处理程序.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();
}
});