gpt4 book ai didi

java - 为什么 MotionEvent.actionToString 不可用?

转载 作者:行者123 更新时间:2023-11-30 03:09:02 24 4
gpt4 key购买 nike

在 Android SDK 中覆盖方法 toString使用 actionToString方法作为具有 public static 修饰符的方法。如果您打开源代码,您必须看到:

 @Override
public String toString() {
StringBuilder msg = new StringBuilder();
msg.append("MotionEvent { action=").append(actionToString(getAction()));

final int pointerCount = getPointerCount();
for (int i = 0; i < pointerCount; i++) {
msg.append(", id[").append(i).append("]=").append(getPointerId(i));
msg.append(", x[").append(i).append("]=").append(getX(i));
msg.append(", y[").append(i).append("]=").append(getY(i));
msg.append(", toolType[").append(i).append("]=").append(
toolTypeToString(getToolType(i)));
}

msg.append(", buttonState=").append(MotionEvent.buttonStateToString(getButtonState()));
msg.append(", metaState=").append(KeyEvent.metaStateToString(getMetaState()));
msg.append(", flags=0x").append(Integer.toHexString(getFlags()));
msg.append(", edgeFlags=0x").append(Integer.toHexString(getEdgeFlags()));
msg.append(", pointerCount=").append(pointerCount);
msg.append(", historySize=").append(getHistorySize());
msg.append(", eventTime=").append(getEventTime());
msg.append(", downTime=").append(getDownTime());
msg.append(", deviceId=").append(getDeviceId());
msg.append(", source=0x").append(Integer.toHexString(getSource()));
msg.append(" }");
return msg.toString();
}

如果您在同一个类中打开actionToString方法:

public static String actionToString(int action) {
switch (action) {
case ACTION_DOWN:
return "ACTION_DOWN";
case ACTION_UP:
return "ACTION_UP";
case ACTION_CANCEL:
return "ACTION_CANCEL";
case ACTION_OUTSIDE:
return "ACTION_OUTSIDE";
case ACTION_MOVE:
return "ACTION_MOVE";
case ACTION_HOVER_MOVE:
return "ACTION_HOVER_MOVE";
case ACTION_SCROLL:
return "ACTION_SCROLL";
case ACTION_HOVER_ENTER:
return "ACTION_HOVER_ENTER";
case ACTION_HOVER_EXIT:
return "ACTION_HOVER_EXIT";
}
int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
switch (action & ACTION_MASK) {
case ACTION_POINTER_DOWN:
return "ACTION_POINTER_DOWN(" + index + ")";
case ACTION_POINTER_UP:
return "ACTION_POINTER_UP(" + index + ")";
default:
return Integer.toString(action);
}
}

但是,当我尝试使用这种方法时

MotionEvent.actionToString(event.getAction);

IDE 告诉我错误。

无法解析方法 actionToString(int);

为什么我会收到这个错误?


链接到类方法:

actionToString method

toString method

最佳答案

此方法存在于早于 API 19 的平台源中,但被隐藏

查看来自 JellyBean 的源代码:

https://android.googlesource.com/platform/frameworks/base/+/jb-mr2.0.0-release/core/java/android/view/MotionEvent.java

/**
* Returns a string that represents the symbolic name of the specified action
* such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
* such as "35" if unknown.
*
* @param action The action.
* @return The symbolic name of the specified action.
* @hide
*/
public static String actionToString(int action) {

注意 JavaDoc 中的 @hide 注释。

在 KitKat 中,注释不再存在:

https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/core/java/android/view/MotionEvent.java

关于java - 为什么 MotionEvent.actionToString 不可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21308315/

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