假设我使用上下文菜单将子节点添加到树视图控件.
(1)我右键单击节点
(2)弹出上下文菜单
(3)然后我点击"添加"菜单项
(4)打开一个dialogBox
(5)我在DialogBox中输入名称,然后按OK
(6)创建一个新节点.
当我点击上下文菜单项时,如何获取当前节点的引用?
我需要这个,因为父对象存储在当前节点的Tag属性中.
我有一个树视图,如果我右键单击任何节点上下文菜单,现在我想添加对应于上下文菜单中的项目的图标.
在尝试将TextView文本复制到剪贴板时,我做错了什么?
我的活动类中的代码:
@Override
public boolean onContextItemSelected(MenuItem item) {
String selectedItem = item.getTitle().toString().trim();
try {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip;
if (selectedItem.equals("Copy Query")) {
clip = ClipData.newPlainText("Query",tv1.getText());
clipboard.setPrimaryClip(clip);
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
错误:
04-17 03:10:54.056: E/AndroidRuntime(503): FATAL EXCEPTION: main
04-17 03:10:54.056: E/AndroidRuntime(503): java.lang.NoClassDefFoundError: android.content.ClipboardManager
04-17 03:10:54.056: E/AndroidRuntime(503): at com.ewe.radixcalculator.CalculatorActivity.onContextItemSelected(CalculatorActivity.java:68)
04-17 03:10:54.056: E/AndroidRuntime(503): at android.app.Activity.onMenuItemSelected(Activity.java:2199)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2744)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:137)
04-17 03:10:54.056: E/AndroidRuntime(503): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:874) …Run Code Online (Sandbox Code Playgroud) 我目前正在运行Windows 7 x64 machine.
我编写了以下代码来右键单击添加上下文菜单:
RegistryKey rKey = Registry.ClassesRoot.OpenSubKey("Directory\\Background\\shell", true);
String[] names = rKey.GetSubKeyNames();
foreach (String s in names)
{
System.Windows.Forms.MessageBox.Show(s);
}
RegistryKey newKey = rKey.CreateSubKey("Your Application");
RegistryKey newSubKey = newKey.CreateSubKey("command");
newSubKey.SetValue("", "C:\\Windows\\System32\\notepad.exe");
newSubKey.Close();
newKey.Close();
rKey.Close();
Run Code Online (Sandbox Code Playgroud)
如果我直接在注册表上重复该过程,它可以工作,但不是通过这个.
我也能够访问注册表,因为我添加了一个片段,告诉列出我需要的所有子键,但根本不添加一个.
我有一个大div(整页),里面有一个较小的div:
<div class="all">
<div class="tiny"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
div.all对我来说就像一块板子,上面div.tiny有一个小矩形.我想在任何时候(或什么都没有)div.all获得RMB 时显示我的特殊上下文菜单.但是当我打开RMB时div.tiny,我不想执行那个"默认"程序,而是执行一些(甚至更特殊的)代码.我尝试过:
jQuery('body').on("contextmenu", ".all", function(){ /* special stuff */});
jQuery('body').off("contextmenu", ".all .tiny"); /* <- tried to turn off my...*/
/*...special stuff for .tiny that way*/
jQuery('body').on("contextmenu", ".tiny", function(){
/* even more special stuff */
});
Run Code Online (Sandbox Code Playgroud)
当我运行它,RMB div.all或其中的元素时,我得到了"特殊的东西".但是,当我点击人民币时,div.tiny我会得到"特殊的东西" (我不想要的)和"更特别的东西"(它太特别了,我怎么也不想要它!).
有解决方案吗
为了让生活困难,我不能改变(第一顺序jQuery()为div.all对,比我的功能div.tiny) -在我真正的项目的事情比较复杂,我必须保持这种为了某些原因(还是它的外观相当合理的-从全球事件精确的).
无法弄清楚我的代码有什么问题:
registerForContextMenu(lv_myhitshotlists);
AdapterContextMenuInfo menuinfo = null;
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
/*menu.setHeaderTitle("Item Operations");
menu.add(0, v.getId(), 0, "Edit Film");
menu.add(0, v.getId(), 0, "Delete Film");*/
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_myfilm_list,menu);
menuinfo = (AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle("Options");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
try{
menuinfo = (AdapterContextMenuInfo) item.getMenuInfo();
AdapterView.AdapterContextMenuInfo info= (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
Long ids = madapter.getItemId(info.position);//what item was selected is ListView
i = ids.intValue();
switch (item.getItemId()) {
case R.id.menu_edit_myfilm:
intHitshotEdit = new Intent(MyHitshotListActivity.this,MyHitshotInfoEditActivity.class);
intHitshotEdit.putExtra("video_id", myList.get(i).getid()); …Run Code Online (Sandbox Code Playgroud) 在我的Windows Phone应用程序中,我有一个数据绑定列表框.我的数据模板包含许多文本块.
如果我点击并按住任何文本块,则会出现上下文菜单.但是,如果我点击并按住列表框项目的空白区域,菜单将不会出现.
例如.如果我选择下面提到的图像中的任何文本区域,则会出现菜单.如果我一直按住名称和日期之间的区域,菜单就不会出现.
如果我在特定列表框项目中保留任何位置,我希望菜单出现.

注意:我包含了上下文菜单
我的xaml代码如下:
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0.25,0.25,0.25,0.25" BorderBrush="{StaticResource PhoneForegroundBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu >
<toolkit:MenuItem
Header="delete"
Click="Delete" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<TextBlock
HorizontalAlignment="Left"
TextWrapping="NoWrap"
Grid.Row="0"
Grid.ColumnSpan="2"
Text="{Binding TEXT}"
VerticalAlignment="Top"
FontWeight="Bold"/>
<TextBlock
HorizontalAlignment="Left"
TextWrapping="NoWrap"
Grid.Row="1"
Grid.Column="0"
Text="{Binding USERNAME}"
VerticalAlignment="Top"
FontSize="{StaticResource PhoneFontSizeSmall}"/>
<TextBlock
HorizontalAlignment="Right"
TextWrapping="NoWrap"
Grid.Row="1"
Grid.Column="1"
Text="{Binding Path=DATE}"
VerticalAlignment="Top"
FontSize="{StaticResource PhoneFontSizeSmall}" />
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
有什么方法可以解决这个问题吗?
谢谢.
我总是觉得当我在stackoverflow上问一个问题就像答案那样......应该是...... RTFM,即使我得到的每一个答案都是友好,耐心和接受的.经过一个下午试图找到答案,我被困住了.我想打开一个Tkinter,文本框和绑定键(键盘快捷键)和一个菜单项,所以我会有一个很好的弹出菜单(也就是上下文菜单),如Window的记事本,你右击,看看
Cut
Copy
Paste
-----
Select All
Run Code Online (Sandbox Code Playgroud)
用Ctrl+ X,Ctrl+ C,Ctrl+ V和Ctrl+ A作为键绑定(我还没弄清楚如何进行撤销).问题是我无法同时使用键绑定和菜单弹出窗口来使用相同的功能.如果我从select_all()的定义中添加或删除"event"参数,则一个有效,但另一个则无效.
from Tkinter import *
# Clears the clipboard and copies the selected text to the it
def copy():
mainwin.clipboard_clear()
mainwin.clipboard_append(mainwin.selection_get())
# Needed for the right click pop-up menu to work, goes with copy()
def popup(event):
popupmenu.post(event.x_root, event.y_root)
# Selects all text, used with the "control a" keybinding
def select_all(event):
textbox.tag_add(SEL, "1.0", END)
textbox.mark_set(INSERT, "1.0")
textbox.see(INSERT) …Run Code Online (Sandbox Code Playgroud) 如何删除/更改 MouseOver 上 MenuItem/ContextMenu 的突出显示颜色?我尝试编辑 ContextMenu 模板并为 MouseOver 上的 MenuItem 设置样式,但默认的 HiglightedColor 仍然存在于 MouseOver 上。
<Style TargetType="{x:Type ContextMenu}">
<Setter Property="SnapsToDevicePixels"
Value="True" />
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="Grid.IsSharedSizeScope"
Value="true" />
<Setter Property="HasDropShadow"
Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border x:Name="Border"
Background="Black"
BorderThickness="0">
<Border.BorderBrush>
<SolidColorBrush Color="Black" />
</Border.BorderBrush>
<StackPanel IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Cycle" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow"
Value="true">
<Setter TargetName="Border"
Property="Padding"
Value="0,0,0,0" />
<Setter TargetName="Border"
Property="CornerRadius"
Value="0" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Background" Value="Transparent"/>
</Trigger>
</ControlTemplate.Triggers> …Run Code Online (Sandbox Code Playgroud) 我想创建一个回收视图。包含如此多产品的购物车,每当您长按产品列表项时,回收视图将显示一个上下文菜单,然后选择删除以将其从产品列表中删除。但是在获取要删除的产品的位置时遇到了一些问题。这是我的回收视图支架代码
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener,View.OnCreateContextMenuListener {
TextView quantity;
TextView name;
TextView price;
ImageView pic;
ImageButton increase;
ImageButton decrease;
int quantityInt=1;
LongClickListener longClickListener;
public int getQuantityInt() {
return quantityInt;
}
void changeQuantityDisplay(int number)
{
quantity.setText(Integer.toString(number));
}
public void setQuantityIntPlus(int quantityInt) {
this.quantityInt = quantityInt+1;
}
public void setQuantityIntMinus(int quantityInt) {
this.quantityInt = quantityInt-1;
}
public MyViewHolder(View itemView) {
super(itemView);
View view=LayoutInflater.from(context).inflate(R.layout.activity_cart,null,false);
name=(TextView)itemView.findViewById(R.id.listproduct_name);
price=(TextView)itemView.findViewById(R.id.listproduct_price);
pic=(ImageView)itemView.findViewById(R.id.listproduct_img);
increase=(ImageButton)itemView.findViewById(R.id.increasebtn);
decrease=(ImageButton)itemView.findViewById(R.id.decreasebtn);
quantity=(TextView) itemView.findViewById(R.id.listproduct_quantity);
itemView.setOnLongClickListener(this);
itemView.setOnCreateContextMenuListener(this);
}
public void setLongClickListener(LongClickListener lc)
{
this.longClickListener=lc;
} …Run Code Online (Sandbox Code Playgroud) 我使用的是contextmenu用turbotable的primeng(6.1.0版本)。
根据网站上的演示,当您右键单击一行时,会出现上下文菜单并选择该行,但是当您在上下文菜单外单击时,菜单消失但该行仍被选中。我想要的是在隐藏上下文菜单时取消选择该行。
见https://www.primefaces.org/primeng/#/table/contextmenu
任何想法如何实现这一目标?
我正在寻找一种解决方案,可以在来自 contenteditable html 的选定文本上创建上下文菜单以创建链接。
工作流程:基本上用户可以编辑网页外的文本(div 中的 contenteditable="true"),如果他们想添加指向所选文本的链接,他们必须使用上下文菜单,在那里他们可以右键单击所选文本并输入 URL从上下文菜单中的输入框中,然后boom,所选文本成为超链接。
欣赏你的方向。
我有一个上下文菜单,当我右键单击页面的右侧部分时,该菜单会被剪切,如下所示:
菜单在页面边缘被剪切,所以我希望菜单移动到光标的另一侧,就像在 Chrome 或其他流行应用程序中一样。我尝试访问 StackOverflow 中的其他页面并尝试一些演示,但它们都说的是上面显示的相同内容。我也尝试评论其他一些帖子,看看他们是否会回答,但仍然没有。
代码:
var menu = document.querySelector('.menu');
function showMenu(x, y) {
menu.style.left = x + 'px';
menu.style.top = y + 'px';
menu.classList.add('menu-show');
}
function hideMenu() {
menu.classList.remove('menu-show');
}
function onContextMenu(e) {
e.preventDefault();
showMenu(e.pageX, e.pageY);
document.addEventListener('mousedown', onMouseDown, false);
}
function onMouseDown(e) {
hideMenu();
document.removeEventListener('mousedown', onMouseDown);
}
document.addEventListener('contextmenu', onContextMenu, false);Run Code Online (Sandbox Code Playgroud)
/* Page */
html {
width: 100%;
height: 100%;
background: radial-gradient(circle, #fff 0%, #a6b9c1 100%) no-repeat;
}
.container {
position: absolute;
top: 20%;
left: 0;
width: 100%; …Run Code Online (Sandbox Code Playgroud)