AndyD273
AndyD273

Reputation: 7279

Getting text from a Listview

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...

Upvotes: 2

Views: 1443

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007624

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.

Upvotes: 1

Related Questions