疑问时......看看Android的源代码!毕竟它是开源的。 :)
混帐://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);
}
因此,答案是,它们是相同的。除了调用setOnCreateContextMenuListener()
之外,registerForContextMenu()
什么都不做。
看起来他们是一样的东西。 – 2011-12-28 03:51:27