Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot save user input to the database in Android
    text
    copied!<p>I am new to android and I am developing an app that saves the user input to the database. However, for some reasons, I cannot see the data that has been been by the user when he pressed the Save Button. Can you help me save the values from this codes?</p> <p><strong>activity.xml</strong></p> <pre><code>&lt;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" &gt; &lt;Spinner android:id="@+id/spn_District" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;Spinner android:id="@+id/spn_Province" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;Spinner android:id="@+id/spn_InfoType" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/txt_Date" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/txt_Remarks" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>Cons_IReport.java (Constructor)</strong></p> <pre><code>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; } </code></pre> <p><strong>DatabaseHandler.java</strong></p> <pre><code>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(); } </code></pre> <p><strong>MainActivity.java</strong></p> <pre><code>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(); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload