对于三星设备的 EditText 中的任何onLongPress
/ onDoubleClick
,该应用都会崩溃。但是,其他设备不会出现此问题。我正在使用旧的Note 2进行调试,并在论坛中发布类似的问题(但已被删除)。很棒,如果有人愿意分享解决方案。
<EditText
android:id="@+id/vse_discountEv"
android:hint="@string/vse_boradcastHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="@dimen/pad_3dp"
android:paddingLeft="@dimen/pad_5dp"
android:paddingRight="@dimen/pad_0dp"
android:paddingBottom="@dimen/pad_5dp"
android:background="@color/transparent"
android:textColorHint="@color/gray_main_light"
android:textSize="@dimen/dim_20dp"
android:scrollbars="horizontal" />
Logcat消息:
10-28 11:08:56.311: E/AndroidRuntime(22228): FATAL EXCEPTION: main
10-28 11:08:56.311: E/AndroidRuntime(22228): Process: com.export, PID: 22228
10-28 11:08:56.311: **E/AndroidRuntime(22228): java.lang.ArithmeticException: divide by zero**
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.widget.Editor.updateShowAsAction(Editor.java:6111)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.widget.Editor$SelectionActionModeCallback.onCreateActionMode(Editor.java:3314)
10-28 11:08:56.311: E/AndroidRuntime(22228): at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onCreateActionMode(PhoneWindow.java:3020)
10-28 11:08:56.311: E/AndroidRuntime(22228): at com.android.internal.app.ActionBarImpl$ActionModeImpl.dispatchOnCreate(ActionBarImpl.java:1021)
10-28 11:08:56.311: E/AndroidRuntime(22228): at com.android.internal.app.ActionBarImpl.startActionMode(ActionBarImpl.java:550)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.app.Activity.onWindowStartingActionMode(Activity.java:5218)
10-28 11:08:56.311: E/AndroidRuntime(22228): at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2632)
10-28 11:08:56.311: E/AndroidRuntime(22228): at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2619)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.view.View.startActionMode(View.java:4752)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.widget.Editor.startSelectionActionMode(Editor.java:1814)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.widget.Editor.performLongClick(Editor.java:1045)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.widget.TextView.performLongClick(TextView.java:10118)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.view.View$CheckForLongPress.run(View.java:19410)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.os.Handler.handleCallback(Handler.java:733)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.os.Handler.dispatchMessage(Handler.java:95)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.os.Looper.loop(Looper.java:146)
10-28 11:08:56.311: E/AndroidRuntime(22228): at android.app.ActivityThread.main(ActivityThread.java:5602)
10-28 11:08:56.311: E/AndroidRuntime(22228): at java.lang.reflect.Method.invokeNative(Native Method)
10-28 11:08:56.311: E/AndroidRuntime(22228): at java.lang.reflect.Method.invoke(Method.java:515)
10-28 11:08:56.311: E/AndroidRuntime(22228): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
10-28 11:08:56.311: E/AndroidRuntime(22228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
10-28 11:08:56.311: E/AndroidRuntime(22228): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
您是如何处理代码中的onLongPress
和onDoubleClick
的?
我在另一个三星设备(SM-A7009)中测试过以下代码,但遗憾的是找不到您所描述的问题。
我使用GestureDetector
来处理onLongPress
和onDoubleClick
事件。
EditText editText1 = new EditText(this);
editText1.setText(R.string.app_name);
final GestureDetectorCompat gestureDetectorCompat = new GestureDetectorCompat(this,
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
super.onLongPress(e);
Log.d(TAG, "onLongPress");
}
@Override
public boolean onDoubleTap(MotionEvent e) {
Log.d(TAG, "onDoubleTap");
return super.onDoubleTap(e);
}
});
editText1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetectorCompat.onTouchEvent(event);
}
});
setContentView(editText1);