0

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.

Deepak
  • 1,238
  • 3
  • 22
  • 47

1 Answers1

2

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();
}
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
  • This only gets me the text displayed in the listitem, but what i want is the rest of the data in that table. Eg if i have a Cursor with id,name,age and i display only name in the listitem , i want to display all 3 in a dialog, your code will only show name. – Deepak Dec 31 '11 at 18:24
  • You have to create a method in your SQLite code that accepts the id of the item in the list and returns the info accordingly. – coder_For_Life22 Dec 31 '11 at 18:26
  • @Adil Soomro Thanks man , your link gave me the answer, my bad for thinking position ment position in the listview while it was actually from the cursor. My bad for not looking at the docs properly. – Deepak Jan 01 '12 at 05:46