// Object class for Product
class Product{
public Product(String title, String short_description, double rating, double price, int image) {
this.title = title;
this.short_description = short_description;
this.rating = rating;
this.price = price;
this.image = image;
}
String title;
String short_description;
double rating;
double price;
int image;
}
//Array List of products
List<Product> productList = new ArrayList<>();
productList.add(new Product("Title1", "Short Description1", 4, 50, R.drawable.ic_thumb_down));
productList.add(new Product("Title2", "Short Description2", 3, 100, R.drawable.ic_thumb_down));
productList.add(new Product("Title3", "Short Description3", 4, 150, R.drawable.ic_thumb_down));
//Adapter
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder>{
List<Integer> resourceList;
public ImageAdapter(List<Integer> resourceList) {
this.resourceList = resourceList;
}
@NonNull
@Override
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new ImageViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_image, viewGroup, false));
}
@Override
public void onBindViewHolder(@NonNull ImageViewHolder imageViewHolder, int i) {
Product product = productList.get(i);
imageViewHolder.imageView.setImageResource(product.image);
// Here you can also use other field like title, description, etc...
}
@Override
public int getItemCount() {
return resourceList.size();
}
class ImageViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
public ImageViewHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.imageView3);
}
}
}