How to get RowID from SQLiteDB in ListView?
<p>I have a ListView that is fed by an SQLiteDB. On each row returned, I have a clickable TextView that onClick should delete the item on that row. So I need to find the sql rowid, so I can call deleteItem(rowid).</p>

<p>I've tried putting in an invisible TextView that I fill with the sql rowid as the ListView is populated, it works. But I set content view to R.layout.list_view and the invisible TextView is in R.layout.list_item (custom layout for each item line), so I can't seem to access it.</p>

<p>How do I go about making this work or is there a better way?</p>

<p>Here is the code that populates the listview:</p>

<pre><code>    private void fillData() {
    // Get all of the notes from the database and create the item list
    Cursor c = mDbHelper.fetchAllNotes();
    startManagingCursor(c);

    String[] from = new String[] { CommonDbAdapter.KEY_NOTES };
    int[] to = new int[] { R.id.text1 };

    // Now create an array adapter and set it to display using our row
    SimpleCursorAdapter notes =
        new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
    setListAdapter(notes);
}
</code></pre>

<p>Here is my current click listener, I'm not sure how to differentiate between a click on the item, which returns the item to another activity and a click on the textview that would delete the item.</p>

<pre><code>    itemList = (ListView) findViewById(android.R.id.list);
    itemList.setTextFilterEnabled(true);
    itemList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView&lt;?&gt; a, View v, int position, long id) {
            Intent intent = new Intent();
            Bundle b = new Bundle();
            b.putString("TEXT", ((TextView)v.findViewById(R.id.text1)).getText().toString());
            intent.putExtras(b);
            setResult(SUCCESS_RETURN_CODE, intent);
            finish();
        }
    });
</code></pre>

<p>I was originally trying to get the rowid and use a simple onClick set in the layout. But had problems getting the rowid.</p>

<pre><code>public void clickDelete(View view) {
    mDbHelper.deleteNote(rowid);
}
</code></pre>
