长按单击列表视图中的列表项时,不会弹出上下文菜单.我已经扩展了基本适配器并使用了视图持有者来实现带有textviews和图像按钮的自定义列表.
adapter = new MyClickableListAdapter(this, R.layout.timeline, mObjectList);
list.setAdapter(adapter);
registerForContextMenu(list);
Run Code Online (Sandbox Code Playgroud)
onCreateContextMenu的实现
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
Log.d(TAG, "Entering Context Menu");
menu.setHeaderTitle("Context Menu");
menu.add(Menu.NONE, DELETE_ID, Menu.NONE, "Delete")
.setIcon(R.drawable.icon);
}
Run Code Online (Sandbox Code Playgroud)
listview的XML就在这里
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多天了.我认为不可能为这样的自定义列表视图注册Context-menu.如果我错了,请纠正我(可能带有示例代码).
现在我正在考虑向列表项添加一个按钮,它会在单击它时显示一个菜单.是否可以通过其他方式使用Dialogs?
任何帮助将非常感激..
我有一个在系统托盘中运行的WPF应用程序.我正在尝试创建一个上下文菜单,当您右键单击托盘中的图标时,该菜单会弹出.这是XAML:
<Window.Resources>
<ContextMenu x:Key="NotifierContextMenu" Placement="MousePoint">
<MenuItem Header="Exit" Click="Menu_Exit"/>
</ContextMenu>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
这是代码隐藏:
void NotifyIcon_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
var menu = this.FindResource("NotifierContextMenu") as ContextMenu;
menu.IsOpen = true;
}
}
protected void Menu_Exit(object sender, RoutedEventArgs e)
{
NotifyIcon.Visible = false;
Application.Current.Shutdown();
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当您右键单击该图标时,它会抛出NotifierContextMenu无法找到的错误.我错过了什么?
我目前正在尝试获取一个自定义WebView,当它被按下较长时间时会显示一个ContextMenu.由于默认WebView类仅在链接为longPressed时显示ContextMenu,因此我编写了自己的类来覆盖此行为:
public class MyWebView extends WebView {
Context context;
GestureDetector gd;
public MyWebView(Context context, AttributeSet attributes) {
super(context, attributes);
this.context = context;
gd = new GestureDetector(context, sogl);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return gd.onTouchEvent(event);
}
GestureDetector.SimpleOnGestureListener sogl =
new GestureDetector.SimpleOnGestureListener() {
public boolean onDown(MotionEvent event) {
return true;
}
public void onLongPress(MotionEvent event) {
// The ContextMenu should probably be called here
}
};
}
Run Code Online (Sandbox Code Playgroud)
这可以正常工作,检测到longPress并调用onLongPress方法,但是在显示ContextMenu时我不知所措.我尝试在我的Activity中按照惯例进行操作:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
MyWebView mwv = (MyWebView) …Run Code Online (Sandbox Code Playgroud) 我有一段时间试图在DataGrid上动态绑定ContextMenu.DataGrid绑定到一个很好的对象列表:
<DataGrid ItemsSource="{Binding DataGridItems}">
Run Code Online (Sandbox Code Playgroud)
对于每个DataGridItem对象,我有一个在属性上公开的MenuItem列表,我想用它来绑定到ContextMenu.我尝试了以下但我认为我遗漏了一些东西:
<DataGrid ItemsSource="{Binding DataGridItems}">
<DataGrid.ContextMenu>
<ContextMenu ItemsSource="{Binding ContextMenuItems}" >
<MenuItem Header="{Binding Name}" Command="{Binding OnClick}"></MenuItem>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid>
Run Code Online (Sandbox Code Playgroud)
public class DataGridItem
{
public ObservableCollection<ContextMenuItem> ContextMenuItems
{
get { return _contextMenuItems; }
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助或指导将不胜感激.
当光标位于任务窗格之外时,不会引发单击事件窗体上下文菜单项.我不知道它是如何工作的.90%的时间,点击是在任务窗格之外.

打开上下文菜单时,子菜单通常显示在任务窗格之外(参见下图).在这种情况下,不会引发上下文菜单中的单击事件.
我绝对不知道如何做这项工作.
有任何想法吗?
我目前使用两个键盘布局与xorg.conf一样
Section "InputClass"
Identifier "Keyboard Defaults"
MatchIsKeyboard "yes"
Option "XkbLayout" "us, de"
Option "XkbOptions" "grp:caps_toggle"
EndSection
Run Code Online (Sandbox Code Playgroud)
现在我想映射AltGr以将其用作上下文菜单键.这可以通过以下方式完成
xmodmap -e "keycode 108 = Menu"
Run Code Online (Sandbox Code Playgroud)
但只修改第一个布局上的键.如何在所有布局上修改它?可以使用高级XkbOption或XkbLayout参数完成某些事情吗?
我有一个ListBox,ItemTemplate绑定到我的项目的ObservableCollection.目前,我正在尝试实现剪切/复制/粘贴/选择所有(为了简短起见,我只会在这里显示selectall ...)
<UserControl.CommandBindings>
<CommandBinding Command="SelectAll" CanExecute="SelectAll_CanExecute" Executed="SelectAll_Executed"/>
</UserControl.CommandBindings>
<ListBox x:Name="listbox"
ItemsSource="{Binding}"
Background="Transparent"
SelectionMode="Extended"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Command="SelectAll" />
</ContextMenu>
</ListBox.ContextMenu>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent">
<CheckBox Name="cbEnabled" IsChecked="{Binding Enabled, Mode=TwoWay}" Margin="0,2,0,0"/>
<TextBlock Text="{Binding Name}" Padding="5,0,0,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
这是canexecute的代码隐藏:
private void SelectAll_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = listbox.Items.Count > 0;
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
当我第一次运行程序并右键单击列表框时,始终禁用"全选"上下文菜单(并且从不调用SelectAll_CanExecute),直到我选择了某些内容.有没有什么方法可以让它像它应该的那样工作?(并且无需自动选择第一项或让用户必须这样做)
谢谢!
版问题:
上下文菜单应动态显示过滤器变量,并使用回调内定义的参数执行函数.通用描述显示正确,但函数调用始终使用last set选项执行.
我尝试过的:
#!/usr/bin/env python
import Tkinter as tk
import ttk
from TkTreectrl import MultiListbox
class SomeClass(ttk.Frame):
def __init__(self, *args, **kwargs):
ttk.Frame.__init__(self, *args, **kwargs)
self.pack(expand=True, fill=tk.BOTH)
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
self.View=MultiListbox(self)
__columns=("Date","Time","Type","File","Line","-","Function","Message")
self.View.configure(columns=__columns, expandcolumns=(0,0,0,0,0,0,0,1))
self.View.bind("", self.cell_context)
self.View.grid(row=0, column=0, sticky=tk.NW+tk.SE)
self.__recordset = []
self.__recordset_filtered = False
#Some dummy values
self.__recordset.append(["Date", "Time", "INFO", "File", "12", "-", "Function", "Message Info"])
self.__recordset.append(["Date", "Time", "DEBUG", "File", "12", "-", "Function", "Message Info"])
self.__recordset.append(["Date", "Time", "WARNING", "File", "12", "-", "Function", "Message Info"])
self.__refresh()
def cleanView(self):
self.View.delete(0, …Run Code Online (Sandbox Code Playgroud) 我需要将参数数据发送到对话框这是我在plugin.js中的代码(右键单击)
editor.addCommand( 'editDialog', {
exec: function( editor) {
CKEDITOR.currentInstance.openDialog('editDialog');
}
});
if ( editor.contextMenu )
{
editor.addMenuGroup( 'myGroup' );
editor.addMenuItem( 'sliderItem',
{
label : 'Edit Gallery',
command : 'editDialog',
group : 'myGroup'
});
editor.contextMenu.addListener( function( element )
{
if ( element ){
element = element.getAscendant( 'wscms-gallery', true );
}
if ( element && !element.isReadOnly() && !element.data( 'cke-realelement' ) ){
return { sliderItem : CKEDITOR.TRISTATE_OFF};
}
return null;
});
}
Run Code Online (Sandbox Code Playgroud)
我想在右键单击并单击editgallery时将任何参数发送到editDialog
最好的祝福
问题:当在recyclelerview中的项目上长按时,无法显示显示"删除"选项的上下文菜单
预期结果:见下图
我几乎就在那里,但我遗漏了一些东西,使contextMenu显示在longClick上.
这是我放在viewHolder中的内容.我不知道我应该添加什么以及在onLongClick事件中显示上下文菜单的位置.
我跳过了一些代码行,并保留了与我的问题相关的代码.
感谢你的帮助,
我的界面处理两种类型的点击
public interface OnItemClickListener{
void onItemClick(int position);
}
public interface OnItemLongClickListener{
void onItemLongClick(int position);
}
Run Code Online (Sandbox Code Playgroud)
查看者代码
public void bindLongClick(final int position, final OnItemLongClickListener onItemLongClickListener) {
itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
onItemLongClickListener.onItemLongClick(position);
return true;
}
});
}
@Override
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo){
//menuInfo is null
Log.v(LOG_TAG, "grrr");
contextMenu.setHeaderTitle("Select The Action");
contextMenu.add(0, view.getId(), 0, "Supprimer");//groupId, itemId, order, title
}
Run Code Online (Sandbox Code Playgroud)
适配器代码
@Override
public void onBindViewHolder(CityListViewholder holder, int …Run Code Online (Sandbox Code Playgroud)