Victor Gallo
Victor Gallo

Reputation: 77

Android loading icon while getting data from Firestore

I'm getting data from Firebase Firestore to populate a ListView, and I would like to show a loading animation while the data is being fetched.

Upvotes: 0

Views: 437

Answers (1)

jagel.id
jagel.id

Reputation: 186

The code for layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <RelativeLayout android:id="@+id/loading"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminate="true" />
    </RelativeLayout>
    <ListView android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        xmlns:android="http://schemas.android.com/apk/res/android" />
</FrameLayout>

The code in java

private void finishLoadList(){
    RelativeLayout loadingLayout = (RelativeLayout) findViewById(R.id.loading);
    ListView listView = (ListView) findViewById(R.id.list_view);

    loadingLayout.setVisibility(View.GONE);
    listView.setVisibility(View.VISIBLE);
}

Upvotes: 1

Related Questions