strange behavior with EditText inside <include> tag

时光毁灭记忆、已成空白 提交于 2020-01-13 18:11:10

问题


I have a view which include another one with the "include" component (see http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html)
There is some EditText inside the included view.

There is some problems with these EditText :

  • I have to tap them 2 times in order to have the keyboard to appear
  • if I long press one of the EditText the app freeze and crash (only on my phone - Samsung galaxy S, not on the emulator)

It does not happen if the Edittext are NOT in a <include> tag ...
Do you have any ideas on this problem ??

regards, Christophe


回答1:


I have the same problem about long click EditText or TextView crash on Samsung device with Android 4.0 up.

The crash log in here

java.lang.ArithmeticException: divide by zero
at android.widget.TextView$SelectionActionModeCallback.onCreateActionMode(TextView.java:10647)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2382)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2322)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
at android.view.View.startActionMode(View.java:3687)
at android.widget.TextView.startSelectionActionMode(TextView.java:10451)
at android.widget.TextView.performLongClick(TextView.java:9570)
at android.view.View$CheckForLongPress.run(View.java:14241)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error

It's because when you long click on text, samsung system will select text to highlight and use onCreateActionMode() to show cut, copy, paste etc button.

If you are in Android 4.0 up, it will show on ActionBar and use the ActionBar theme style in your app's style.xml. And I found my

"@android:style/Widget.Holo.ActionButton"

set minWidth to zero, cause samsung system calculate action button position resulted

java.lang.ArithmeticException: divide by zero

Finally set minWidth to not zero, the problem solved.




回答2:


I wanted to comment on the answer given below (https://stackoverflow.com/a/11966733/1777346) but don't have enough reputation points yet!

We also ran into the same "java.lang.ArithmeticException: divide by zero" exception on Samsung devices (didn't test other devices.. all Samsung). It would occur when long-pressing existing text in an EditText field.

The solution below worked.. we had the following style defined. Changing minWidth to "1" fixed this.

<style name="ActionButtonStyle" parent="@android:style/Widget.Holo.Light.ActionButton">
    <item name="android:minWidth">0dp</item>


来源:https://stackoverflow.com/questions/7731412/strange-behavior-with-edittext-inside-include-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!