简体   繁体   English

如何从包含多行的列表中创建上下文菜单

[英]How to create context menu from the list which contain multi line

I have some question, If I create listview like this 我有一个问题,如果我像这样创建列表视图

[text] [文本]

[text] [文本]


[text] [文本]

[text] [文本]


each list contain 2 lines and I want to make context menu when I try long press to each list it will show context menu 每个列表包含2行,当我尝试长按每个列表时,我想创建上下文菜单,它将显示上下文菜单

So how to create context menu from the list which contain multi line.... 那么如何从包含多行的列表中创建上下文菜单。

Are you registering the ListView for the context menu using 您是否正在使用上下文菜单注册ListView

registerForContextMenu(listView);

or are you creating your own context menu using listView.setOnItemLongClickListener(onItemSelctedListener()) ? 还是使用listView.setOnItemLongClickListener(onItemSelctedListener())创建自己的上下文菜单?

In both cases, there shouldn't be a problem because they act reacting to each element of the ListView 在这两种情况下,都应该没有问题,因为它们会对ListView的每个元素做出反应

However, if you are using 但是,如果您使用

listView.setOnLongClickListener(onLongClickListener)

then you are registering it to the whole list, and it doesn't matter where you press in the list, its going to bring the same context menu. 那么您将其注册到整个列表中,而在列表中按什么位置都无所谓,它会带来相同的上下文菜单。

I hope that helps you with something. 希望对您有所帮助。

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

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