recyclerview不显示项目

Amm*_*ser 0 android android-recyclerview

我在recyclerview中显示了一个自定义列表项目
只有一个项目显示在此回收中

在此输入图像描述

主要活动

 AdapterforRecycleview adapter  = new AdapterforRecycleview(this,dataItemList);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);
    recyclerView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

适配器 在此输入图像描述 在此输入图像描述

Sah*_*hil 5

你还应该添加LayoutManagerrecyclerView.

 recyclerView.setLayoutManager(new LinearLayoutManager(this));
Run Code Online (Sandbox Code Playgroud)

如果您使用XML制作,请参阅以下内容:

<android.support.v7.widget.RecyclerView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layoutManager="android.support.v7.widget.GridLayoutManager" >
Run Code Online (Sandbox Code Playgroud)

该类必须扩展android.support.v7.widget.RecyclerView $ LayoutManager并具有默认构造函数或带有签名的构造函数(android.content.Context,android.util.AttributeSet,int,int).

如果名称以"."开头,则应用程序包将作为前缀.否则,如果名称包含'.',则类名被假定为完整的类名.否则,回收器视图包名称(android.support.v7.widget)是前缀.

我希望它有所帮助.