开发者

Getting text from a Listview

开发者 https://www.devze.com 2023-01-06 07:19 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消