文本菜单打开时抓住了列表项的TextView值 [英] Grabbing the list item TextView value when ContextMenu is opened

查看:129
本文介绍了文本菜单打开时抓住了列表项的TextView值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个的ListView 单/短按一下,我可以这样做:

On a ListView single/short click, I can do this:

protected void onListItemClick(ListView listView, View v, int position,
        long id) {
    tvInt = reviews.get(position);
}

我将如何做到这一点的一个文本菜单?我的的ListView 仅包含一个的TextView

编辑:我要抢的TextView 的ListView ,而不是<$ C $的价值C>文本菜单。

I want to grab the value of the TextView in the ListView, not the ContextMenu.

推荐答案

菜单项包从那里,你可以提取位置额外信息 ListView中点击行,然后只需用code你在 onListItemClick 回调:

The MenuItem packs extra information from where you could extract the position of the clicked row in the ListView and then simply use the code you used in the onListItemClick callback:

@Override
public boolean onContextItemSelected(MenuItem item) {
     AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
     int clickedPosition = info.position;
     tvInt = reviews.get(position);
     // ...

相同的信息, ContextMenuInfo ,如果你想获得字符串建立时是在 onCreateContextMenu 回调可在文本菜单

The same information, ContextMenuInfo, is available in the onCreateContextMenu callback if you want to get the String when building the ContextMenu.

这篇关于文本菜单打开时抓住了列表项的TextView值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆