Note that there are some explanatory texts on larger screens.

plurals
  1. POEditText input saved in Database
    primarykey
    data
    text
    <p>I'm really new to Android and i'd like to save the Input of my Edittext into my Database. Here's my Database:</p> <pre><code> package de.retowaelchli.filterit.database; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class ADFilterDBAdapter { public static final String ROW_ID = "_id"; public static final String NAME = "name"; public static final String KEYWORD = "keyword"; public static final String CACHE = "cache"; private static final String DATABASE_TABLE = "adfilter"; private DatabaseHelper mDbHelper; private SQLiteDatabase mDb; private final Context mCtx; private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DBAdapter.DATABASE_NAME, null, DBAdapter.DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } /** * Constructor - takes the context to allow the database to be * opened/created * * @param ctx * the Context within which to work */ public ADFilterDBAdapter(Context ctx) { this.mCtx = ctx; } /** * Open the cars database. If it cannot be opened, try to create a new * instance of the database. If it cannot be created, throw an exception to * signal the failure * * @return this (self reference, allowing this to be chained in an * initialization call) * @throws SQLException * if the database could be neither opened or created */ public ADFilterDBAdapter open() throws SQLException { this.mDbHelper = new DatabaseHelper(this.mCtx); this.mDb = this.mDbHelper.getWritableDatabase(); return this; } /** * close return type: void */ public void close() { this.mDbHelper.close(); } /** * Create a new car. If the car is successfully created return the new * rowId for that car, otherwise return a -1 to indicate failure. * * @param name * @param model * @param year * @return rowId or -1 if failed */ public long createADFilter(String name, String keyword, String cache){ ContentValues initialValues = new ContentValues(); initialValues.put(NAME, name); initialValues.put(KEYWORD, keyword); initialValues.put(CACHE, cache); return this.mDb.insert(DATABASE_TABLE, null, initialValues); } /** * Delete the car with the given rowId * * @param rowId * @return true if deleted, false otherwise */ public boolean deleteADFilter(long rowId) { return this.mDb.delete(DATABASE_TABLE, ROW_ID + "=" + rowId, null) &gt; 0; //$NON-NLS-1$ } /** * Return a Cursor over the list of all cars in the database * * @return Cursor over all cars */ public Cursor getAllADFilter() { return this.mDb.query(DATABASE_TABLE, new String[] { ROW_ID, NAME, KEYWORD, CACHE }, null, null, null, null, null); } /** * Return a Cursor positioned at the car that matches the given rowId * @param rowId * @return Cursor positioned to matching car, if found * @throws SQLException if car could not be found/retrieved */ public Cursor getADFilter(long rowId) throws SQLException { Cursor mCursor = this.mDb.query(true, DATABASE_TABLE, new String[] { ROW_ID, NAME, KEYWORD, CACHE}, ROW_ID + "=" + rowId, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } /** * Update the car. * * @param rowId * @param name * @param keyword * @param cache * @return true if the note was successfully updated, false otherwise */ public boolean updateADFilter(long rowId, String name, String keyword, String cache){ ContentValues args = new ContentValues(); args.put(NAME, name); args.put(KEYWORD, keyword); args.put(CACHE, cache); return this.mDb.update(DATABASE_TABLE, args, ROW_ID + "=" + rowId, null) &gt;0; } } </code></pre> <p>Its a Copy of an Other Database i change to work on my own.</p> <p>Heres my layout.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1"&gt; &lt;TextView style="@style/NormalFont" android:text="@string/adconfig" android:layout_weight="0.05" android:clickable="false" /&gt; &lt;TextView style="@style/SmallFont" android:text="@string/adname" android:layout_weight="0.03" /&gt; &lt;EditText android:layout_width="match_parent" android:id="@+id/ADConfigName" android:layout_weight="0.05" android:layout_height="25dp" android:layout_marginBottom="20dp"&gt; &lt;requestFocus&gt;&lt;/requestFocus&gt; &lt;/EditText&gt; &lt;TextView style="@style/SmallFont" android:text="@string/adkeyword" android:layout_weight="0.03" /&gt; &lt;EditText android:layout_width="match_parent" android:id="@+id/ADConfigKeyword" android:layout_weight="0.05" android:layout_height="25dp" android:layout_marginBottom="20dp"&gt; &lt;requestFocus&gt;&lt;/requestFocus&gt; &lt;/EditText&gt; &lt;TextView style="@style/SmallFont" android:text="@string/adcache" android:layout_weight="0.03" /&gt; &lt;RadioGroup android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:checkedButton="@+id/adcache_true" android:id="@+id/adcache" android:gravity="center" &gt; &lt;RadioButton android:text="Yes" android:id="@+id/adcache_true" android:layout_width="80dip" android:layout_height="wrap_content" &gt; &lt;/RadioButton&gt; &lt;RadioButton android:text="No" android:id="@+id/adcache_falsh" android:layout_width="80dip" android:layout_height="wrap_content"&gt; &lt;/RadioButton&gt; &lt;/RadioGroup&gt; &lt;TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/ADConfigMainsite" android:layout_weight="0.76" android:gravity="bottom"&gt; &lt;TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ADConfigMainsite" android:onClick="onClickADConfigSave" android:layout_weight="0.05" android:gravity="bottom"&gt; &lt;TextView android:text="@string/adconfigsave" style="@style/NormalFont" android:gravity="bottom"/&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; </code></pre> <p>And heres my Activity:</p> <pre><code>package de.retowaelchli.filterit; import android.app.Activity; import android.os.Bundle; public class ADFilterConfigActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.autodelete_config); } } </code></pre> <p>What do i have to do that it saves my Input text into my Database. Thx in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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