我目前有一个生成弹出菜单的按钮,我试图找到一种方法来检测菜单中的项目何时被长按。一旦我检测到用户点击并保持在菜单项上,我想提示他们询问他们是否要删除该项。
我了解如何以编程方式删除菜单项,这里的帖子是remove popup menu item programmatically。我遇到的问题是检测菜单项上的长按。
据我所知,没有setMenuOnItemLongClickListener(),只有setMenuOnItemClickListener(),所以我离开了制作自定义解决方案以检测popupmenu项目的长按?
答案 0 :(得分:1)
将操作视图设置为菜单项并通过getActionView()
获取。对于此视图,您可以附加长按侦听器。
您也可以通过xml将操作视图附加到菜单项:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(ChimmerIntentService.this).setContentTitle(app_name).setSmallIcon(icon_ID).setContentText(message)
.setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true).setContentIntent(pendingIntent).build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notificationTag, notificationID, notification);
In this method we pass notification id every time you need to pass unique id for each notification.
notificationManager.notify(notificationTag, notificationID, notification);
May be you pass the same notification id every time when a new notification is comming because of same id it replace the privious one.