Search code examples
androidlistviewcursor

OnListItemClick - how to access data through corresponding cursoritem?


I use a CustomCursorAdapter to populate a ListView. Also the onitemclicklistener works for reading text from the clicked ListItem.

I only display partial data from the cursor used..

How can i access the corresponding item in the database , when a listitem is clicked so that i can display all the data in a toast or dialog box.


Solution

  • What is your Object about, what do you want to do on list item click?

    Posting the details will help us to answer but here is a simple code to show a tost:

    protected void onListItemClick(ListView l, View v, int position, long thisID)
    {
        super.onListItemClick(l, v, position, thisID);
        // Get the item that was clicked
        String keyword = (String)this.getListAdapter().getItem(position);
        Toast.makeText(Activity.this, keyword, Toast.LENGHT_SHORT).show();
    }