简体   繁体   English

获取已调用上下文菜单项的项目的视图

[英]getting the view of item on which context menu item has been called

I am creating a list of TextView on which I am creating a context menu. 我正在创建要在其上创建上下文菜单的TextView列表。 However how do I know on which TextView the context menu was called? 但是,我如何知道在哪个TextView上调用了上下文菜单?

Here is my code http://snipt.org/vfyj7 这是我的代码http://snipt.org/vfyj7

You can get all necessary information from MenuItem: 您可以从MenuItem获取所有必要的信息:
AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
item.position contains selected item position. item.position包含选定的项目位置。

In this particular override for your activity, you can get the id of the textView that was clicked and then do necessary operations based on the textView. 在此活动的特定替代中,您可以获取被单击的textView的ID,然后根据textView进行必要的操作。

  @Override
    public boolean onContextItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        return super.onContextItemSelected(item);

        if(item.getItemId()==R.id.textView1) {
       //do something with 1st textview
     }    
     else if(item.getItemId()==R.id.textView2) {
      //do something with textview 2
    } and so on....
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM