在Android SDK中重寫方法toString使用actionToString方法作爲公共靜態修飾符。如果開放的源代碼,你必須看到:爲什麼MotionEvent.actionToString不可用?
@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告訴我有關錯誤的信息。
Cannot resolve method actionToString(int);
爲什麼我收到這個錯誤?
鏈接到類方法:
actionToString method
toString method
可能是你不建設分鐘-SDK 19 - 此法剛剛在SDK中補充說:http://developer.android .com/reference/android/view/MotionEvent.html#actionToString%28int%29 –
' '在我的清單中。作爲一個附加的sourse - sdk 18. –
將它設置爲19和它將工作 –