我如何得到一个ListView项文本集 [英] How do I get the text set on a ListView item

查看:98
本文介绍了我如何得到一个ListView项文本集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的事情什么
我有一个ListView几个项目。当我渴望preSS的项目我有几个选项会弹出一个文本菜单。在这些选项是共享任务。当用户选择共享任务,我希望能有他们长期pressed进行检索,并传递给方法的项目的标题/文本。

What I want to do I have several items in a ListView. When I longpress an item I have a contextmenu which pops up with several options. On of these options is "Share task". When the user selects "Share task" I want to have the Title/Text of the item they long-pressed to be retrieved and passed to a method.

什么是我已经成功地做​​到这一点至今
我设法让该文本菜单被召入使用下面的方法显示在ListView项目的ID和位置。

What's I've managed to do so far I have managed to get the id and position of the item in the listView which the contextmenu was called up using the method show below.

@Override
public boolean onContextItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
    case R.id.menuShare :
        //Identify list item on which editing needs to be performed
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

        //METHOD TO SHARE TASK NEEDS TO GO HERE
        shareTask();
        return true;
    }
    return super.onContextItemSelected(item);
}

我需要帮助
我想不通我怎么能现在得到在其上的ContextMenu被称为项目的文本/标题。我打算再此字符串传递给shareTask()函数来启动一个选择器。我已经通过了该标题将被作为例如电子邮件的标题。

What I need help with I can't figure out how I can now get the text/title of the item on which the contextmenu was called. I intend to then pass this string to the shareTask() function to fire up a chooser. The title I have passed will then be used for example as the title of an email.

非常感谢你提前!

推荐答案

您应使用以下code获取列表项的文本:

You should use the following code to get text of list item:

AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
//list item's text on which long-pressed is performed
String text = yourListView.getAdapter().getItem(info.position).toString();

这篇关于我如何得到一个ListView项文本集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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