i am retrieving data from my database such as any data field.
i am able to get fields such as location, country and address.
what i am struggling with is getting the image url from the database in order to insert it into my picasso function.
here is my java code:
private FirebaseFirestore firebaseFirestore;
private RecyclerView FirestoreList;
private FirestoreRecyclerAdapter adapter;
FirestoreList = findViewById(R.id.recycler_view);
firebaseFirestore = FirebaseFirestore.getInstance();
Query q = firebaseFirestore.collection("Shops");
//recycle options
FirestoreRecyclerOptions<Shop> options = new FirestoreRecyclerOptions.Builder<Shop>()
.setQuery(q, Shop.class)
.build();
adapter = new FirestoreRecyclerAdapter<Shop, ShopViewHolder>(options) {
@NonNull
@Override
public ShopViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.shop_item,parent,false);
return new ShopViewHolder(view);
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onBindViewHolder(@NonNull ShopViewHolder holder, int position, @NonNull Shop model) {
holder.list_name.setText(model.getName());
holder.list_location.setText(model.getLocation());
//here is where i should be able to get my image url from the database.
i tried doing it this way but there is always and error or incompatibility.
holder.header_img.setText(model.getShopHeaderImg());
holder.header_img.setImageURI(model.getShopHeaderImg());
//all of these give me an error, so what is the correct methodology to retrieve the image url??
}
};
FirestoreList.setHasFixedSize(true);
FirestoreList.setLayoutManager(new LinearLayoutManager(this));
FirestoreList.setAdapter(adapter);
here is where i should be getting my values:
private class ShopViewHolder extends RecyclerView.ViewHolder {
private TextView list_name;
private TextView list_location;
private ImageView header_img;
public ShopViewHolder(@NonNull View itemView) {
super(itemView);
Shop MyShop = new Shop();
String image = MyShop.getShopHeaderImg();
list_name = itemView.findViewById(R.id.list_name);
list_location = itemView.findViewById(R.id.list_location);
header_img = itemView.findViewById(R.id.header_img);
Picasso.get().load(image).into(header_img);
}
}
this is my shop class:
public class Shop {
private String name;
private String country;
private String address;
private String location;
private String ShopHeaderImg;
//private int priority;
public Shop(){
}
public Shop(String name, String country, String address, String location, String ShopHeaderImg) {
this.name = name;
this.country = country;
this.address = address;
this.location = location;
this.ShopHeaderImg = ShopHeaderImg;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getShopHeaderImg() {
return ShopHeaderImg;
}
public void setShopHeaderImg(String ShopHeaderImg) {
this.ShopHeaderImg = ShopHeaderImg;
}
}
how will i be able to retrieve the image url into the getShopHeaderImg() method
check this
put this method inside your viewHolder
public void setHeaderImage(final Context c , final String Image){
final ImageView headerImg = (ImageView)itemView.findViewById(R.id.headerImage);
Picasso.with(c).load(Image).into(headerImg);
}
and use the method inside onBindViewHolder
holder.setHeaderImage(getApplicationContext(),model.getShopHeaderImg());