tags:

views:

38

answers:

1

I have a ListView that gets filled from a cursor (using rawQuery) that I need to get the text of the selected item from on click.

protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Intent mViewChaptersIntent = new Intent(this, ViewWeb.class);
    String s = ((TextView) l.getItemAtPosition(position)).getText().toString(); // Tried this, didn't work.
    mViewChaptersIntent.putExtra("extension", s);
    mViewChaptersIntent.putExtra("itmClicked", String.format("%d", id));
    startActivity(mViewChaptersIntent);
}

But I'm not sure about the right way to do it. The getItemAtPosition that I've seen in other posts doesn't seem to work...

+1  A: 

getItemAtPosition() should return you a Cursor that is positioned at the specified row. You will then need to call getString() to retrieve whatever column you are looking for.

CommonsWare
That seemed to do it.For future reference: `String s = (String)((Cursor)l.getItemAtPosition(position)).getString(2);`
AndyD273
How could be any faster without generics?
ktingle