我们常见的显示数据的控件listview,下面我简述 一下RecyclerView的使用及简单的现实数据
首先在activity_main.xml中
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
然后我们准备数据,写一个bean,展示一个图片和文字
public class Product {
private int img;
private String title;
public Product(int img, String title) {
this.img = img;
this.title = title;
}
public int getImg() {
return img;
}
public void setImg(int img) {
this.img = img;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
然后我们还需要一个adapter类