简体   繁体   中英

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. However how do I know on which TextView the context menu was called?

Here is my code http://snipt.org/vfyj7

You can get all necessary information from MenuItem:
AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
item.position contains selected 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.

  @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....
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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