I'm attempting to display an image from my SQLite database on a recycler view. The images are links I scraped from a second-hand car website. So far I was able to display the name, price, year and location. I looked at Picasso on how to do it but I can't seem to find examples on this platform on how to integrate it on a recyclerview. Does anyone have an idea of how to display it?
class SearchViewHolder extends RecyclerView.ViewHolder {
public TextView name, price, year, location;
public ImageView image;
public SearchViewHolder(@NonNull View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.name);
price = (TextView) itemView.findViewById(R.id.price);
year = (TextView) itemView.findViewById(R.id.year);
location = (TextView) itemView.findViewById(R.id.location);
image = (ImageView) itemView.findViewById(R.id.car_img);
}
}
public class SearchAdapter extends RecyclerView.Adapter<SearchViewHolder> {
private Context context;
private List<Products> products;
public SearchAdapter(Context context, List<Products> products) {
this.context = context;
this.products = products;
}
@NonNull
@Override
public SearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View itemView = inflater.inflate(R.layout.layout_item,parent, false);
return new SearchViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull SearchViewHolder holder, int position) {
holder.name.setText(products.get(position).getName());
holder.price.setText(products.get(position).getPrice());
holder.year.setText(products.get(position).getYear());
holder.location.setText(products.get(position).getLocation());
}
@Override
public int getItemCount() {
return products.size();
}
}