David
David

Reputation: 839

Images loaded from firestore with Picasso not showing in cardview

I am loading images into CardView with Picasso from Firebase but the images are not showing

I am following this guide: How to display data from Firestore in a RecyclerView with Android?. However images are still not visible.

cardview layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_marginVertical="8dp"
    app:cardCornerRadius="6dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageCardView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitCenter"
            android:contentDescription="@string/user_image" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:textAlignment="center"
            android:textColor="#fff"
            android:textSize="20sp" />

    </LinearLayout>

</android.support.v7.widget.CardView>

the adapter I am using

adapter = new FirestoreRecyclerAdapter<Post, PostViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull PostViewHolder postViewHolder, int position, @NonNull Post post) {
                postViewHolder.setPostImage(post.getImageUrl_1());
            }

            @NonNull
            @Override
            public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.card_view_layout, parent, false);
                return new PostViewHolder(view);
            }
        };
        recyclerView.setAdapter(adapter);

The code to load images.

void setPostImage(final String imageURL) {
    ImageView imageView = view.findViewById(R.id.imageCardView);
    //imageView.setImageBitmap(getBitmapFromURL(imageURL));
    Picasso.with(view.getContext())
           .load(imageURL)
           .into(imageView);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(view.getContext(), imageURL, Toast.LENGTH_SHORT).show();
        }
    });
}

I would expect that the images from my Firebase Storage would load into my cardViews, but they are not visible. However I know that they are loading into the image views because the correct number of cardviews are loading based on the number of pictures in storage and when clicking on the imageview the correct urls are shown in the toast. If there is anything else I should add please let me know. Any help would be greatly appreciated.

Edit:

I added the .placeholder() to Picasso and it is now showing the placeholder however when I click the image the toast still displays the url to storage.

Upvotes: 0

Views: 778

Answers (3)

David
David

Reputation: 839

I found the issue I was having. Turns our the link that I was sending to Picasso was not the one I was looking for. The following question best describes my issue: How to get URL from Firebase Storage getDownloadURL. However, Thanks to Dor for providing help using Picasso properly.

Upvotes: 1

joseph.dev89
joseph.dev89

Reputation: 21

Since Android P, network security config is needed in order to handle all http requests, maybe is something related to that. You can check this solutions

Upvotes: 0

Dor
Dor

Reputation: 657

It's seems like picasso changed the function with to get link so maybe try something like this

Picasso.get()
    .load(imageURL)
    .placeholder(some place holder image)
    .fit()
    .into(imageView);

Upvotes: 0

Related Questions