- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
registerForContextMenu 有什么区别:
Registers a context menu to be shown for the given view (multiple views can show the context menu). This method will set the View.OnCreateContextMenuListener on the view to this activity
Call registerForContextMenu() and pass it the View you want to give a context menu. When this View then receives a long-press, it displays a context menu.
和 setOnCreateContextMenuListener :
Register a callback to be invoked when the context menu for this view is being built. If this view is not long clickable, it becomes long clickable.
用哪个?关于可点击的长内容:两者都在做同样的事情......
谢谢
最佳答案
如有疑问...请查看 Android 源代码!毕竟它是开源的。 :)
git://android.git.kernel.org/platform/frameworks/base.git/core/java/android/view/View.java:
/**
* Register a callback to be invoked when the context menu for this view is
* being built. If this view is not long clickable, it becomes long clickable.
*
* @param l The callback that will run
*
*/
public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) {
if (!isLongClickable()) {
setLongClickable(true);
}
mOnCreateContextMenuListener = l;
}
git://android.git.kernel.org/platform/frameworks/base.git/core/java/android/app/Activity.java:
/**
* Registers a context menu to be shown for the given view (multiple views
* can show the context menu). This method will set the
* {@link OnCreateContextMenuListener} on the view to this activity, so
* {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
* called when it is time to show the context menu.
*
* @see #unregisterForContextMenu(View)
* @param view The view that should show a context menu.
*/
public void registerForContextMenu(View view) {
view.setOnCreateContextMenuListener(this);
}
所以,答案是它们是一样的。 registerForContextMenu()
除了调用 setOnCreateContextMenuListener()
什么都不做。
关于android - registerForContextMenu 和 setOnCreateContextMenuListener 的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8651620/
根据我能够从谷歌收集到的信息,如果我希望在长按所述 View 时调用 OnCreateContextMenu,则我必须在 View 上调用 RegisterForContextMenu。这不会发生。
我正在尝试使用 float 上下文菜单,我想知道是否可以通过按 ImageView 中的图像来激活此菜单? 我的第一个问题是如何处理 registerForContextMenu 和 ImageVie
这个问题的答案可能很明显,但让我很头疼。我有一个简单的 LinearLayout,其中包含一个 ListView。我这样做:onCreate public void onCreate(Bundle b
我想在用户单击适配器内的 View 时使用上下文菜单。问题是每个 View 的 OnClick 都在一个不是 Activity 的类中 [它是一个扩展 BaseAdapter 的类],在 public
registerForContextMenu 有什么区别: Registers a context menu to be shown for the given view (multiple view
在Activity类中,有一个名为registerForContextMenu(View view)的方法。 android 文档解释说,该方法用于注册一个 上下文菜单 为给定 View 显示(多个
这个问题之前有人问过,主要是引用了ListActivity,所以一直没能使用他们的方案。 OTOH,我正在使用包含 gridview 的正常 Activity (由于其上的其他 UI 元素)。当我对某
我已经尝试寻找解决方案,但没有找到符合我的情况的任何解决方案。我有一个扩展 FragmentActivity 的 MainActivity 和多个 ListFragment。我将 PagerSlidi
在 onCreate 中,我将线性布局 View 附加到变量 activeView。然后调用 registerForContextMenu(activeView)。看起来一切正常,创建了上下文菜单,可
我是一名优秀的程序员,十分优秀!