2015-10-14 61 views
0

我知道这个问题已被问了很多次,但没有解决我的问题。我正在尝试在RecyclerView中使用CardView,但目前还没有运气。 这里是我的代码:如何修复错误膨胀类Android.support.v7.widget.CardView

<?xml version="1.0" encoding="utf-8"?> 
<Android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.Android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    card_view:cardCornerRadius="4dp" 
    card_view:cardBackgroundColor="#AA66CC" 
    card_view:cardElevation="10dp" 
    android:id="@+id/cv"> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center"> 

    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="40dp" 
    android:id="@+id/list_item" 
    android:text="asdasd asdasd tt" 
    /> 
</RelativeLayout> 

</Android.support.v7.widget.CardView> 

,这里是我的适配器:

public class ApprovalListAdapter extends Adapter<ApprovalListAdapter.ViewHolder> { 

private String[] dataSource; 
private Context mContext; 
public ApprovalListAdapter(String[] dataArgs, Context context){ 
    dataSource = dataArgs; 
    mContext = context; 

} 
@Override 
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    // create a new view 
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.approval_list_row, parent, false); 

    ViewHolder viewHolder = new ViewHolder(view); 
    return viewHolder; 


} 

@Override 
public void onBindViewHolder(ViewHolder holder, int position) { 
    holder.textView.setText(dataSource[position]); 
} 


@Override 
public int getItemCount() { 
    return dataSource.length; 
} 

public static class ViewHolder extends RecyclerView.ViewHolder{ 
    protected TextView textView; 
    protected CardView cv; 
    public ViewHolder(View itemView) { 
     super(itemView); 
     cv = (CardView) itemView.findViewById(R.id.cv); 
     textView = (TextView) itemView.findViewById(R.id.list_item); 

    } 
    } 
} 

我还添加所需要的依赖

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:23.0.1' 
    compile 'com.android.support:support-v4:23.0.1' 
    compile 'com.android.support:recyclerview-v7:23.0.1' 
    compile 'com.android.support:cardview-v7:23.0.1' 
    compile 'com.android.support:design:23.0.1' 
    compile project(":volley") 
} 

即CardView工作完全正常时,其不RecyclerView。

+0

没有行为意味着你得到什么确切的问题? – Pavan

+0

'android.view.InflateException:二进制XML文件行#2:错误充气类Android.support.v7.widget.CardView' @pavan – Miqe

+0

它没有显示任何东西或显示至少一个项目 – Pavan

回答

2

您似乎有个案错误,cardview标记以小写字母开头。 在XML中,将:

<Android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" ... </Android.support.v7.widget.CardView>

有:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" ... </android.support.v7.widget.CardView>

+0

谢谢,这解决了我的问题! – Miqe

+0

谢谢!我输入'cardview'而不是'CardView'并且也得到了问题。 – sqd

相关问题