0

我正在使用 Action Bar 模板开发一个 android 应用程序。一切正常,但是当我双击任何 EditText 字段时,应用程序会出现运行时错误,然后崩溃。当我单击一次时,什么也没有发生,一切都很好。这是布局(片段)

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:gravity="center"
    tools:ignore="UselessParent" >

    <RelativeLayout 
        android:id="@+id/addrun_layout_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">
        <TextView
            android:id="@+id/textView1"
            android:layout_width="150dp"
            android:layout_height="40dp"
            android:background="#B0B0B0"
            android:gravity="center"
            android:text="@string/date"
            android:textSize="22sp" />

        <EditText
            android:id="@+id/date"
            android:layout_width="120dp"
            android:layout_height="40dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/textView1"
            android:background="#B0B0B0"
            android:ems="10"
            android:inputType="date"
            android:gravity="center"
            android:textSize="22sp" >
        </EditText>
    </RelativeLayout>
    <GridLayout
        android:id="@+id/gridLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/addrun_layout_date"
        android:layout_marginTop="20dp"
        android:columnCount="2" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_marginBottom="10dp"
            android:background="#838383"
            android:gravity="center"
            android:text="@string/distance"
            android:textColor="#FFFFFF"
            android:textSize="24sp" />

        <EditText
            android:id="@+id/distance"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_marginLeft="20dp"
            android:gravity="center"
            android:background="#FFFFFF"
            android:inputType="numberDecimal"
            android:selectAllOnFocus="true"
            android:clickable="false"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_marginBottom="10dp"
            android:background="#838383"
            android:gravity="center"
            android:text="@string/time"
            android:textColor="#FFFFFF"
            android:textSize="24sp" />

        <EditText
            android:id="@+id/time"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_marginLeft="20dp"
            android:gravity="center"
            android:background="#FFFFFF"
            android:inputType="numberDecimal"
            android:selectAllOnFocus="true"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="150dp"
            android:layout_height="50dp"
             android:gravity="center"
            android:layout_marginBottom="30dp"
            android:background="#838383"
            android:text="@string/calories"
            android:textColor="#FFFFFF"
            android:textSize="22sp" />

        <EditText
            android:id="@+id/caloris"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_marginLeft="20dp"
            android:gravity="center"
            android:background="#FFFFFF"
            android:inputType="number"
            android:selectAllOnFocus="true"
            android:textSize="24sp" />

        <Button
            android:id="@+id/addButton"
            android:layout_width="100dp"
            android:layout_height="35dp"
            android:layout_gravity="center"
            android:background="#A71926"
            android:text="@string/add"
            android:textColor="#FFFFFF" />

        <Button
            android:id="@+id/clearButton"
            android:layout_width="100dp"
            android:layout_height="35dp"
            android:layout_gravity="center"
            android:background="#A71926"
            android:onClick="clear"
            android:text="@string/clear"
            android:textColor="#FFFFFF" />
    </GridLayout>

</RelativeLayout>

我可以触摸该字段,更改其值,没有问题,只是当我双击它时,应用程序崩溃,并在日志中留下以下错误消息:

> 12-14 05:41:51.496: E/AndroidRuntime(1681): FATAL EXCEPTION: main
12-14 05:41:51.496: E/AndroidRuntime(1681): Process: prv.adt.ejree, PID: 1681
12-14 05:41:51.496: E/AndroidRuntime(1681): android.view.InflateException: Binary XML file line #17: Error inflating class com.android.internal.view.menu.ActionMenuItemView
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.BaseMenuPresenter.createItemView(BaseMenuPresenter.java:157)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:176)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:163)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:438)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1052)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:87)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:216)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.BaseMenuPresenter.getMenuView(BaseMenuPresenter.java:72)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.view.menu.ActionMenuPresenter.getMenuView(ActionMenuPresenter.java:154)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.widget.ActionBarContextView.initForMode(ActionBarContextView.java:230)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.app.ActionBarImpl.startActionMode(ActionBarImpl.java:455)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.app.Activity.onWindowStartingActionMode(Activity.java:5005)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2375)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2362)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.View.startActionMode(View.java:4536)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.widget.Editor.startSelectionActionMode(Editor.java:1551)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.widget.Editor$SelectionModifierCursorController.onTouchEvent(Editor.java:3656)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.widget.Editor.onTouchEvent(Editor.java:1036)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.widget.TextView.onTouchEvent(TextView.java:7691)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.View.dispatchTouchEvent(View.java:7706)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.View.dispatchPointerEvent(View.java:7886)
12-14 05:41:51.496: E/AndroidRuntime(1681):     at android.view.ViewRootImpl$Vie

有什么解释吗?

4

1 回答 1

0

您的问题不在您的 xml 布局中,而是由于 android ActionMenuItemViewxml 布局,它无法处理您通过 Java 代码应用到它的自定义,因此您在扩展操作栏菜单项时犯了一些错误,请看这里了解您忘记了什么或错过了什么。

于 2014-12-14T12:09:54.340 回答