好的,所以我知道你可以在用户长时间点击一个项目时创建一个上下文菜单...但我可以这样做,这样当用户在项目或屏幕上说双击时会出现弹出菜单吗?谢谢
在我的应用程序中,我的主布局中有一个ListView.在相应的Activity中,我在onCreate中有以下内容:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
app = (MyTallyKeeperApplication) getApplication();
adapter = new TallyItemListAdapter(this, app.getTallyItems());
setListAdapter(adapter);
registerForContextMenu(getListView());
}
Run Code Online (Sandbox Code Playgroud)
ListView中的每个项都是TallyItemView类型,继承自LinearLayout.我用来夸大上下文菜单的代码是:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
Log.i(MyTallyKeeperMain.class.getSimpleName(), "onCreateContextMenu");
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.item_menu, menu);
}
Run Code Online (Sandbox Code Playgroud)
理论上,当您长按某个项目时,会显示一个上下文菜单,您可以选择编辑该项目或将其删除.但是当我长按一个项目时,没有显示任何内容.关于如何解决这个问题的任何想法?
我有一个从ListActivity继承并使用AndroidAnnotations的活动.虽然.onListItemClick工作正常,但列表项的上下文菜单根本不会显示,甚至.onCreateContextMenu不会被调用,但是.onListItemClick在长时间点击列表项后会触发.这是我的代码:
@OptionsMenu(R.menu.places)
@EActivity(R.layout.places)
public class PlacesPicker extends ListActivity {
private static String[] DATA_SOURCE = { PlacesDB.PLACE_NAME, PlacesDB.PLACE_DESC };
private static int[] DATA_DESTINATION = { R.id.place_name, R.id.place_desc };
public static ListView lv;
@Bean
PlacesDB db;
Cursor cursor;
@AfterInject
public void init() {
cursor = db.getPlaces(null, null);
startManagingCursor(cursor);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.place_item, cursor, DATA_SOURCE, DATA_DESTINATION);
setListAdapter(adapter);
lv = getListView();
registerForContextMenu(lv);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) …Run Code Online (Sandbox Code Playgroud) Swing 文本组件没有带有剪切/复制/粘贴等功能的上下文菜单。我想添加一个,以便它表现得更流畅,就像一个本机应用程序。我为此编写了一个菜单,效果很好。我使用以下方法将其添加到每个文本框:
someTextBox.setComponentPopupMenu(TextContextMenu.INSTANCE);
Run Code Online (Sandbox Code Playgroud)
问题是,到处添加这个很烦人。其次,如果我忘记在某个地方的文本框,应用程序就会不一致。第三,我无法将其添加到我无法控制创建代码的文本框中,例如来自JOptionPane.showInputDialog或JFileChooser对话框的文本框。
有没有办法覆盖JTextComponent应用程序范围的默认上下文菜单?我知道这将是一种令人毛骨悚然的远距离行动,但我对此表示同意。也欢迎对菜单本身发表评论。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public class TextContextMenu extends JPopupMenu implements ActionListener {
public static final TextContextMenu INSTANCE = new TextContextMenu();
private final JMenuItem itemCut;
private final JMenuItem itemCopy;
private final JMenuItem itemPaste;
private final JMenuItem itemDelete;
private final JMenuItem itemSelectAll;
private TextContextMenu() {
itemCut = newItem("Cut", 'T');
itemCopy = newItem("Copy", 'C');
itemPaste = newItem("Paste", 'P');
itemDelete = newItem("Delete", 'D');
addSeparator();
itemSelectAll = newItem("Select …Run Code Online (Sandbox Code Playgroud) 我有这种方法:
void showAllSongsMenu() {
if (rebuilding) {
Toast.makeText(MusicPlayerActivity.this,
"Database rebuild in progress, please wait!",
Toast.LENGTH_SHORT).show();
return;
}
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.allsongs_list,
null);
allSongs = new PopupWindow(popupView, LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT, true);
Button allSongsMenu = (Button) allSongs.getContentView().findViewById(
R.id.close_all_songs_menu);
allSongs.setBackgroundDrawable(MusicPlayerActivity.this.getResources()
.getDrawable(R.drawable.unknown_artist));
allSongs.setFocusable(true);
allSongsMenu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
allSongs.dismiss();
}
});
ListView lv = (ListView) allSongs.getContentView().findViewById(
R.id.all_songs_list);
//registerForContextMenu(lv);
lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener(){
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Song options");
menu.add(0, v.getId(), …Run Code Online (Sandbox Code Playgroud) 我正在使用TreeTableView,并且我想根据所选行内的数据更改与上下文菜单关联的菜单项。
假设我有一个结构如下的表:
访客
不休
在此表中,我们可以比喻说我们有两个根节点,分别是“访问者”和“ Chatters”。现在,我想有两个带有不同选项的上下文菜单。可以说,针对访问者的上下文菜单有一个项目是“邀请聊天”,另一个上下文菜单处理聊天者,并且具有不同的选项,例如:“踢”,“禁止”等。我的问题是如何实现这种情况?我应该在哪里使用这些上下文菜单?我应该将它们用于单元格,行还是表格?
我有下一个代码:
<p-dataTable [contextMenu]="cm" [value]="Usuarios" selectionMode="single" [(selection)]="selectedRecord" resizableColumns="true" [rows]="10" [paginator]="true" [pageLinks]="3" [rowsPerPageOptions]="[5,10,20]" scrollable="true" scrollWidth="100%">
<p-column [sortable]="true" field="id" header="ID" [style]="{'width':'50px'}"></p-column>
<p-column [sortable]="true" field="dni" header="DNI" [style]="{'width':'80px'}"></p-column>
<p-column [sortable]="true" field="ap_paterno" header="Apellido Paterno" [style]="{'width':'120px'}"></p-column>
<p-column [sortable]="true" field="ap_materno" header="Apellido Materno" [style]="{'width':'120px'}"></p-column>
<p-column [sortable]="true" field="nombres" header="Nombres" [style]="{'width':'120px'}"></p-column>
<p-column [sortable]="true" field="fecnac" header="Fecha de Nac" [style]="{'width':'150px'}"></p-column>
<p-column [sortable]="true" field="est_civil" header="Estado Civil" [style]="{'width':'120px'}"></p-column>
<p-column [sortable]="true" field="fec_ingreso" header="Fecha de Ingreso" [style]="{'width':'120px'}"></p-column>
<p-column [sortable]="true" field="movil" header="Movil" [style]="{'width':'100px'}"></p-column>
<p-column [sortable]="true" field="fijo" header="Fijo" [style]="{'width':'90px'}"></p-column>
<p-column [sortable]="true" field="direccion" header="Dirección" [style]="{'width':'180px'}"></p-column>
<p-column [sortable]="true" field="distrito" header="Distrito" [style]="{'width':'200px'}"></p-column> …Run Code Online (Sandbox Code Playgroud) (IDE:Visual C++ 6.0)
我想使用列表控件来创建一个类似于 Windows 任务管理器的程序。
将通过api接收到的进程的信息(item)添加进去,通过列表控件显示出来。
我想要做的是右键单击特定项目,然后会出现一个像真正的任务管理器一样的对话框。
搜索的结果好像是使用了 OnContextMenu(CWnd*, CPoint) 函数,但是不明白是怎么工作的。
我希望你提供一个简单的例子。
谢谢 :)
我正在尝试禁用右键单击特定div. 在渲染中我做
<div onContextMenu={(e) => {
console.log(e);
e.preventDefault();
e.stopPropagation();
return false
}}>
Run Code Online (Sandbox Code Playgroud)
它确实打印,所以我知道它是附加的,但它仍然会在 firefox ESR 60.8.0 中弹出,即使它在 chrome 中被阻止。
原因:我有一个手持台,我向其中添加了自定义上下文菜单,并且在 Firefox 中,本机上下文菜单呈现在我的顶部。一旦我弄清楚如何在 Firefox 中的任何位置阻止上下文菜单,我会将其应用于自定义渲染器中的 handsontable
编辑:开始赏金是因为其他黑客都没有为我工作,这是一个关于罕见版本的 Firefox 的非常晦涩的案例
contextmenu ×10
android ×4
java ×2
angular ×1
c++ ×1
firefox ×1
handsontable ×1
java-8 ×1
javafx-8 ×1
javascript ×1
listactivity ×1
listcontrol ×1
listview ×1
menu ×1
mfc ×1
popup ×1
reactjs ×1
right-click ×1
swing ×1
windows ×1
wix ×1