gpt4 book ai didi

android - registerForContextMenu 和 setOnCreateContextMenuListener 的区别?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:25:31 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com