Add dependencies to build.gradle
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
-----------------------------------------------------------------------------------------------------------------------------------
In activity_main.xml
<? xml version ="1.0" encoding ="utf-8" ?>
<RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android"
xmlns: app ="http://schemas.android.com/apk/res-auto"
xmlns: tools ="http://schemas.android.com/tools"
android :layout_width ="match_parent"
android :layout_height ="match_parent"
tools :context =".MainActivity" >
<androidx.recyclerview.widget.RecyclerView
android :id ="@+id/recyclerView"
android :layout_width ="match_parent"
android :layout_height ="match_parent" />
</RelativeLayout>
------------------------------------------------------------------------------------------------------------------------------------
In list_layout.xml
<? xml version ="1.0" encoding ="utf-8" ?>
<LinearLayout xmlns: android ="http://schemas.android.com/apk/res/android"
android :layout_width ="match_parent"
android :layout_height ="match_parent" >
<androidx.cardview.widget.CardView
android :layout_width ="match_parent"
android :layout_height ="wrap_content"
android :layout_margin ="5dp" >
<RelativeLayout
android :layout_width ="match_parent"
android :layout_height ="wrap_content"
android :padding ="8dp" >
<ImageView
android :id ="@+id/imageView"
android :layout_width ="120dp"
android :layout_height ="90dp"
android :padding ="4dp" />
<TextView
android :id ="@+id/textViewTitle"
android :layout_width ="wrap_content"
android :layout_height ="wrap_content"
android :layout_marginLeft ="5dp"
android :layout_toRightOf ="@id/imageView"
android :text ="Apple MacBook Air Core i5 5th Gen - (8 GB/128 GB SSD/Mac OS Sierra)"
android :textAppearance ="@style/Base.TextAppearance.AppCompat.Small"
android :textColor ="#000000" />
<TextView
android :id ="@+id/textViewShortDesc"
android :layout_width ="wrap_content"
android :layout_height ="wrap_content"
android :layout_below ="@id/textViewTitle"
android :layout_marginLeft ="5dp"
android :layout_marginTop ="5dp"
android :layout_toRightOf ="@id/imageView"
android :text ="13.3 Inch, 256 GB"
android :textAppearance ="@style/Base.TextAppearance.AppCompat.Small" />
<TextView
android :id ="@+id/textViewRating"
android :layout_width ="wrap_content"
android :layout_height ="wrap_content"
android :layout_below ="@id/textViewShortDesc"
android :layout_marginLeft ="5dp"
android :layout_marginTop ="5dp"
android :layout_toRightOf ="@id/imageView"
android :background ="@color/colorPrimary"
android :paddingLeft ="15dp"
android :paddingRight ="15dp"
android :text ="4.7"
android :textAppearance ="@style/Base.TextAppearance.AppCompat.Small.Inverse"
android :textStyle ="bold" />
<TextView
android :id ="@+id/textViewPrice"
android :layout_width ="wrap_content"
android :layout_height ="wrap_content"
android :layout_below ="@id/textViewRating"
android :layout_marginLeft ="5dp"
android :layout_marginTop ="5dp"
android :layout_toRightOf ="@id/imageView"
android :text ="INR 56990"
android :textAppearance ="@style/Base.TextAppearance.AppCompat.Large"
android :textStyle ="bold" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
------------------------------------------------------------------------------------------------------------------------------------
Do it again by selecting "Getter", then you'll see the following
public class Product {
private int id;
private String title, shortdesc;
private double rating;
private double price;
private int image;
public Product(int id, String title, String shortdesc, double rating, double price, int image) {
this.id = id;
this.title = title;
this.shortdesc = shortdesc;
this.rating = rating;
this.price = price;
this.image = image;
}
public int getId() {
return id;
}
public String getTitle() {
return title;
}
public String getShortdesc() {
return shortdesc;
}
public double getRating() {
return rating;
}
public double getPrice() {
return price;
}
public int getImage() {
return image;
}
}
------------------------------------------------------------------------------------------------------------------------------------
RecyclerView.Adapter
RecyclerView
------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------
留言列表