Benni
Benni

Reputation: 969

FirebaseListAdapter populated with images

I'm trying to populate a GridView with images from a directory in Firebase storage using FirebaseListAdapter.

I have a simple layout for the griditem.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="2">

<ImageView
    android:id="@+id/image_1"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="170dp"
    android:layout_marginRight="5dp"/>

<ImageView
    android:id="@+id/image_2"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="170dp"
    android:layout_marginRight="5dp"/>

going into my activities layout:

<GridView
        android:id="@+id/image_grid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:verticalSpacing="0dp"
        android:horizontalSpacing="0dp"
        android:stretchMode="columnWidth"
        android:numColumns="2">

    </GridView>

and I've implemented an adapter:

@Override
protected void onStart() {
    super.onStart();

    imageAdapter = new FirebaseListAdapter<String>() {
        @Override
        protected void populateView(View v, String model, int position) {



        }
    };
}

But I honestly can't work out how I'm going to populate it with the adapter. The directory from where it'll fetch images is at "rootstorage/images/userID/images1,2,3etc" so somehow I need the adapter to load all the images from that "userID" dir and into the GridView.

Upvotes: 1

Views: 246

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317487

Firebase Storage doesn't have an API that lets you list files at a path. Instead, every time you upload something Firebase Storage, you should also record its file path or download URL in a database that you can query when you need the list of files. You query that database to get the list of URLs to use to display the images in your app.

Upvotes: 1

Related Questions