本文介绍了Android开放文本菜单上的短点击+通过单击的项目细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 lv.setOnItemClickListener(new OnItemClickListener() {
             @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
              TextView text = (TextView) view.findViewById(R.id.btitle);
              registerForContextMenu(text);
              view.showContextMenu();
              }
            });
       }

     @Override
     public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
       super.onCreateContextMenu(menu, v, menuInfo);
       TextView text = (TextView) v.findViewById(R.id.btitle);
       CharSequence itemTitle = text.getText();
       menu.setHeaderTitle(itemTitle);

       MenuInflater inflater = getMenuInflater();
       inflater.inflate(R.menu.context_menu, menu);

     }

您好,

我想打开一个文本菜单上的短项点击。我已经成功地这样做只是如果我添加registerForContextMenu(getListView());的地方,但,这也触发文本菜单上长按(我不希望发生的事情)。

I'm trying to open a contextMenu on short item click.I've managed to do so only if I add registerForContextMenu(getListView()); somewhere but this also triggers contextMenu on long click (which I don't want to happen).

试过view.showContextMenu(),但它不会做任何事情,除非我添加了registerForContextMenu(getListView()); 。试图注册点击的项目,然后再调用showContextMenu(),但什么也没做,以及...

Tried view.showContextMenu() but it doesn't do anything unless i add the registerForContextMenu(getListView()); . tried registering the clicked item first and then call the showContextMenu() but didn't do anything as well...

另外,我想获得的点击物品图像+文字这样我就可以使用它们的文本菜单。

Also, I want to get the clicked item image + text so I can use them in the contextMenu.

鸭preciate的帮助!

Appreciate the help!

推荐答案

解决方法:

@Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
      super.onCreateContextMenu(menu, v, menuInfo);
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.context_menu, menu);

      AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
      long itemID = info.position;
      menu.setHeaderTitle("lior" + itemID);
    }

在AdapterView.AdapterContextMenuInfo信息(AdapterView.AdapterContextMenuInfo)menuInfo;给你更多的细节了解列表项点击。然后你可以使用info.id,info.position等,以获取详细信息,并利用它们的行动(编辑,删除...)。

the "AdapterView.AdapterContextMenuInfo info (AdapterView.AdapterContextMenuInfo)menuInfo;" gives you more details about the list item clicked.Then you can use info.id, info.position and so on to retrieve the details and use them actions (edit, delete...).

这篇关于Android开放文本菜单上的短点击+通过单击的项目细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:06