如何从firebase数据库中检索图像url



我正在从数据库中检索数据,例如任何数据字段。

我可以获得诸如地点、国家和地址之类的字段。

我正在努力从数据库中获取图像url,以便将其插入到我的picasso函数中。

这是我的java代码:

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);

这是我应该得到我的价值观的地方:

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);
}
}

这是我的商店舱位:

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;
}
}

如何将图像url检索到getShopHeaderImg((方法中

检查此

将此方法放入您的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);
}

并使用onBindViewHolder 内部的方法

holder.setHeaderImage(getApplicationContext(),model.getShopHeaderImg());

相关内容

  • 没有找到相关文章

最新更新