Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I select a column from database and show it in a android textView?
    text
    copied!<p>I am new in android programming, I try to show the result of my select query in a text view, I have been trying to do it in these last 3 day, but it still just does not work; and here are my codes:</p> <pre><code> f.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub db.open(); Cursor c = db.getWord(find.getText().toString()); c.moveToFirst(); String[] from = {DBManager.KEY_ENGLISH}; int[] to = {R.id.TVTrans}; SimpleCursorAdapter a = new SimpleCursorAdapter(StartingPoint.this, R.layout.dic, c, from, to); show.setText(a.convertToString(c)); db.close(); } }); </code></pre> <p>this is my db functions, and getWord(String bahahsaIndo) in the last is the function that i want to use</p> <pre><code>public class DBManager { public static final String KEY_ROWID = "_id"; public static final String KEY_BAHASA = "bahasa"; public static final String KEY_ENGLISH = "english"; private static final String TAG = "DBAdapter"; private static final String DATABASE_NAME = "dict"; private static final String DATABASE_TABLE = "words"; private static final int DATABASE_VERSION = 1; private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " (_id integer primary key autoincrement, " + KEY_BAHASA + " text not null, " + KEY_ENGLISH + " text not null" + ");"; private final Context context; private DatabaseHelper DBHelper; private SQLiteDatabase db; public DBManager(Context ctx) { this.context = ctx; DBHelper = new DatabaseHelper(context); } private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS titles"); onCreate(db); } } //---opens the database--- public DBManager open() throws SQLException { db = DBHelper.getWritableDatabase(); return this; } //---closes the database--- public void close() { DBHelper.close(); } //---insert a title into the database--- public long insertTitle(String bahasaIndo, String englishLang) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_BAHASA, bahasaIndo); initialValues.put(KEY_ENGLISH, englishLang); return db.insert(DATABASE_TABLE, null, initialValues); } //---retrieves all the titles--- public Cursor getAll() { return db.rawQuery("select * from " + DATABASE_TABLE, null); /*return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_BAHASA, KEY_ENGLISH, null}, null, null, null, null, null);*/ } public Cursor getWord(String bahasaIndo){ return db.rawQuery("SELECT * FROM " + DATABASE_TABLE + " WHERE " + KEY_BAHASA + " = '" + bahasaIndo+"'", null); } </code></pre> <p>}</p> <p>Finally, this is my xml files</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;EditText android:id="@+id/ETFind" android:layout_height="wrap_content" android:text="Type the word that you want to find...." android:layout_width="wrap_content"&gt; &lt;/EditText&gt; &lt;TextView android:text="@+id/TextView01" android:id="@+id/TVTrans" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;/TextView&gt; &lt;Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/bFind" android:text="Find"&gt; &lt;/Button&gt; &lt;Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/bSpeak" android:text="Speak"&gt; &lt;/Button&gt; &lt;/LinearLayout&gt; </code></pre> <p>Any help will be appriciated :)</p>
 

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