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...
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.
精彩评论