我无法显示Cloud Firestore中的图像

时间:2019-11-06 11:05:24

标签: android firebase google-cloud-firestore

My Firebase Cloud database Structure

我的活动代码

private FirebaseFirestore firebaseFirestore  = FirebaseFirestore.getInstance();
private CollectionReference collectionReference;
private void getData() {

    mAuth = FirebaseAuth.getInstance();
    FirebaseUser currentUser = mAuth.getCurrentUser();
    mobileNumber = currentUser.getPhoneNumber();

    collectionReference = firebaseFirestore.collection("OWNERS_DATA");
    query = collectionReference.document(mobileNumber).collection("BUILDING_DATA");

    FirestoreRecyclerOptions<AddBuilding> options = new FirestoreRecyclerOptions.Builder<AddBuilding>()
            .setQuery(query, AddBuilding.class)
            .build();

    adapter = new OwnerBuildingListAdapter(options);

    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(adapter);
}
@Override
public void onStart() {
    super.onStart();
    adapter.startListening();
}

@Override
public void onStop() {
    super.onStop();
    adapter.stopListening();
}

在我的Pojo类中,我给出了一个空的构造函数,构造函数,getter和setter。 我在.setquery(query,AddBuilding.class)行遇到错误。 我的适配器类看起来像这样。

public class OwnerBuildingListAdapter extends FirestoreRecyclerAdapter<AddBuilding, OwnerBuildingListAdapter.OwnerBuildingListHolder> {
public OwnerBuildingListAdapter(FirestoreRecyclerOptions<AddBuilding> options) {
    super(options);
}

@Override
protected void onBindViewHolder(OwnerBuildingListHolder ownerBuildingListHolder, int i, AddBuilding addBuilding) {

    ownerBuildingListHolder.buildingName.setText(addBuilding.getBuildingName());
    String imageUrl = addBuilding.getImageUrl();
    Picasso.get().load(imageUrl).into(ownerBuildingListHolder.buildingImage);

}

@NonNull
@Override
public OwnerBuildingListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_cardview, parent, false);
    return new OwnerBuildingListHolder(view);
}

class OwnerBuildingListHolder extends RecyclerView.ViewHolder{

    TextView buildingName;
    ImageView buildingImage;

    public OwnerBuildingListHolder(@NonNull View itemView) {
        super(itemView);

        buildingName = itemView.findViewById(R.id.text_view);
        buildingImage = itemView.findViewById(R.id.image_view);

    }
}
}

如果我运行程序,我得到的是输出,但没有得到图像

您能帮我吗?

1 个答案:

答案 0 :(得分:1)

将firestore ui依赖项更新为最新版本:

{{1}}

在这里检查:

https://github.com/firebase/FirebaseUI-Android