0

I can add to a db and list as a listview. When I click a list item using onListItemClick, what statement do I need to get the value?

String[] from = new String[] {NotesDbAdapter.KEY_BODY, NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_NUMBER};
int[] to = new int[] {R.id.toptext, R.id.middletext, R.id.circle};  
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.row, notesCursor, from, to);
setListAdapter(notes);

//some other code
protected void onListItemClick(ListView l, View v, int position, long thisID)
{
    super.onListItemClick(l, v, position, thisID);
    **String **resposponseid** = Activity2.getData();**
}

I have responseid for every row unique which I want to use when I click on list position. So how to get responseid when I click on list?

Zoe
  • 27,060
  • 21
  • 118
  • 148
SRam
  • 2,832
  • 4
  • 45
  • 72
  • Did you search for examples on google? – Rajath Apr 09 '11 at 07:10
  • @rajath yes sir but not help full.. actually sir i am new in android and java so if u help me it would be vv thaks full....sir pls pls – SRam Apr 09 '11 at 07:15
  • which data u had display in listview? – Niranj Patel Apr 09 '11 at 07:18
  • i had save data in list view using simple cursor adapter now i want to fetch this data according to position pls look at code pls pls..pls – SRam Apr 09 '11 at 07:59
  • This similar question has a good answer that is actually relevant to SimpleCursorAdapter: http://stackoverflow.com/questions/6156836/get-selected-item-from-listview-bound-with-simplecursoradapter – murrayc May 23 '14 at 10:54

2 Answers2

0

In the onListItemClick method, the parameter int position is exactly what you're looking for. The list is filled by an ArrayAdapter which utilizes some List (let's say an ArrayList) to get Views for each row.

The fact that the View in each row can be pretty complicated (not consist of a single value), leads to the way it is implemented, and you don't get the value itself, but the position in the list. What you need to do to get the value is to query that ArrayList (its get(int index) method) you used to fill the ListView with the position param.

Ilya Saunkin
  • 18,934
  • 9
  • 36
  • 50
0

In general, it should something like this. You will need to tailor it to suit your needs.

@Override
protected void onListItemClick(ListView l, View v, int position, long thisID)
{
    super.onListItemClick(l, v, position, thisID);
    // Get the item that was clicked
    Object o = this.getListAdapter().getItem(position);
    String keyword = o.toString();
}

I would suggest you go through a tutorial to learn, especially if you are new to Android and Java. Here's one - Android ListView and ListActivity - Tutorial.

Rajath
  • 11,787
  • 7
  • 48
  • 62