设置默认卡应用程序时停止

时间:2017-05-29 11:08:42

标签: android xml android-cardview

我的设置默认卡查看我的应用程序有问题。当我创建我的卡时,我设置了我的卡列表。然后单击我的菜单集选项默认我的应用程序已停止。

我的错误日志

  

android.view.InflateException:二进制XML文件行#2:二进制XML文件行#2:错误扩充类                                                                                在android.view.LayoutInflater.inflate(LayoutInflater.java:539)                                                                                在android.view.LayoutInflater.inflate(LayoutInflater.java:423)                                                                                在com.novum.smrtkarta.adapter.CardAdapter.onCreateViewHolder(CardAdapter.java:57)                                                                                在com.novum.smrtkarta.adapter.CardAdapter.onCreateViewHolder(CardAdapter.java:34)                                                                                在android.support.v7.widget.RecyclerView $ Adapter.createViewHolder(RecyclerView.java:6367)                                                                                在android.support.v7.widget.RecyclerView $ Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5555)                                                                                在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5440)                                                                                在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5436)

CardAdapter.class

   @Override
    public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        Context context = parent.getContext();
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View view;
        if (viewType == 1) {
            view = layoutInflater.inflate(R.layout.item_card_selected, parent, false); //this line show error
            return new CardViewHolder(view);
        } else {
            view = layoutInflater.inflate(R.layout.item_cardview_default, parent, false);
            return new CardViewHolder(view);
        }
    }



item_card_selected.xml

    <android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:clickable="true"
    android:elevation="100dp"
    android:foreground="?android:attr/selectableItemBackground"
    app:cardBackgroundColor="@drawable/card_view_border"
    app:cardCornerRadius="4dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="10dp"
        android:weightSum="1">

        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src="@drawable/qrcode" />

        <LinearLayout
            android:id="@+id/dataStatic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:padding="5dp">


            <TextView
                android:id="@+id/nameCard"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="@style/TextAppearance.FontPath"
                android:textColor="@color/blackColor"
                android:textSize="13sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/dateText"
                    style="@style/labelTextView"
                    android:text="@string/data_dodania" />

                <Space
                    android:layout_width="12dp"
                    android:layout_height="15dp" />

                <TextView
                    android:id="@+id/setDateText"
                    style="@style/labelTextView"
                    android:text="02.02.2017" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/dateExpiration"
                    style="@style/labelTextView"
                    android:text="Data ważności: " />

                <Space
                    android:layout_width="20dp"
                    android:layout_height="15dp" />

                <TextView
                    android:id="@+id/setDateExpirationText"
                    style="@style/labelTextView"
                    android:text="23/20" />

            </LinearLayout>
        </LinearLayout>


        <ImageView
            android:id="@+id/menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:padding="20dp"
            android:src="@drawable/ic_more_black" />
    </LinearLayout>
</android.support.v7.widget.CardView>

item_cardview_default.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:clickable="true"
    android:elevation="100dp"
    android:foreground="?android:attr/selectableItemBackground"
    app:cardCornerRadius="4dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="10dp"
        android:weightSum="1">

        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src="@drawable/qrcode" />

        <LinearLayout
            android:id="@+id/dataStatic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:padding="5dp">


            <TextView
                android:id="@+id/nameCard"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="@style/TextAppearance.FontPath"
                android:textColor="@color/blackColor"
                android:textSize="13sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/dateText"
                    style="@style/labelTextView"
                    android:text="@string/data_dodania" />

                <Space
                    android:layout_width="12dp"
                    android:layout_height="15dp" />

                <TextView
                    android:id="@+id/setDateText"
                    style="@style/labelTextView"
                    android:text="02.02.2017" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/dateExpiration"
                    style="@style/labelTextView"
                    android:text="Data ważności: " />

                <Space
                    android:layout_width="20dp"
                    android:layout_height="15dp" />

                <TextView
                    android:id="@+id/setDateExpirationText"
                    style="@style/labelTextView"
                    android:text="23/20" />

            </LinearLayout>
        </LinearLayout>


        <ImageView
            android:id="@+id/menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:src="@drawable/ic_more_black" />
    </LinearLayout>
</android.support.v7.widget.CardView>

1 个答案:

答案 0 :(得分:0)

在onCreateViewHolder中,您有item_cardview_default,但文件名为item_card_default.xml。