我在设置默认卡查看我的应用程序时遇到问题。当我创建我的卡时,我设置了与我的卡一起列出。接下来单击我的菜单集选项默认我的应用程序已停止。
我的错误日志
android.view.InflateException: 二进制 XML 文件行 #2: 二进制 XML 文件行 #2: 膨胀类时出错 at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at com.novum.smrtkarta.adapter.CardAdapter.onCreateViewHolder(CardAdapter.java:57) at com.novum.smrtkarta.adapter.CardAdapter.onCreateViewHolder(CardAdapter.java:34) at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6367) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5555) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5440) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5436)
卡适配器.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>
在onCreateViewHolder中,你有item_cardview_default,但文件的名称为item_card_default.xml。