Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid query where clause on ListView
    text
    copied!<p>I created a <code>ListView</code> with a <code>CursorAdapter</code>, populated by a table of my db. After I added a <code>ContextMenu</code> that with a long click on the desired line of <code>ListView</code> pick info from my table.</p> <p>The problem is that: I can not collect the information of that single line of <code>ListView</code>, each line gives me the same result. I think I do something wrong in query.</p> <p><code>onCreate</code>:</p> <pre><code>private void createTabRegistry(SQLiteDatabase db) { String sql = "CREATE TABLE {0} ({1} INTEGER PRIMARY KEY AUTOINCREMENT, {2} TEXT,{3} INTEGER,{4} TEXT,{5} TEXT,{6} TEXT, {7} TEXT);"; db.execSQL(MessageFormat.format(sql, TabRegistry.TABLE_NAME, TabRegistry._ID,TabRegistry.TYPE, TabRegistry.DATE, TabRegistry.STATUS, TabRegistry.NUMBER, TabRegistry.MESSAGE, TabRegistry.OTHER)); } </code></pre> <p>My query in db class:</p> <pre><code>public Cursor getRegistry2(long id) { return (getReadableDatabase().query( TabRegistry.TABLE_NAME, TabRegistry.COLUMNS, TabRegistry._ID + " = " + id, null, null, null, null, null)); } </code></pre> <p>id of <code>ContextMenu</code> in my activity:</p> <pre><code> AdapterView.AdapterContextMenuInfo info= (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); id = getListAdapter().getItemId(info.position); </code></pre> <p>My cursor in the activity class:</p> <pre><code>Cursor c3 = databaseHelper.getRegistry2(id); if (c3 != null) { c3.moveToFirst(); } dbnumber = (c3.getString(c3.getColumnIndex(TabRegistry.NUMBER))); </code></pre> <p>How do I assign to <code>dbnumber</code> string the value of the line of <code>ListView</code> that wonder?</p> <p>EDIT code that works, but reset the view of listview....</p> <pre><code>Cursor c3 = (Cursor) getListAdapter().getItem(info.position); startManagingCursor(c3); aaaaa = c3.getString(c3.getColumnIndex(TabRegistry.NUMBER)); c3.close(); </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