Open In App

How to Create Dynamic Bottom Sheet Dialog in Android using Firebase Firestore?

Last Updated : 06 Jan, 2023
Like Article

Bottom Sheet Dialog is one of the famous Material UI Component which is used to display the data or notifications in it. We can display any type of data or any UI component in our Bottom Sheet Dialog. In this article, we will take a look at the implementation of dynamic Bottom Sheet Dialog in Android using Firebase Firestore

What we are going to build in this article? 

We will be building a simple application in which we will be displaying a simple bottom sheet dialog, and we will display the data inside that bottom sheet dynamically from Firebase. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Create Dynamic Bottom Sheet Dialog in Android using Firebase Firestore Sample GIF

Step by Step Implementation

Step 1: Create a new Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.  

Step 2: Connect your app to Firebase

After creating a new project. Navigate to the Tools option on the top bar. Inside that click on Firebase. After clicking on Firebase, you can get to see the right column mentioned below in the screenshot.

Inside that column Navigate to Firebase Cloud Firestore. Click on that option and you will get to see two options on Connect app to Firebase and Add Cloud Firestore to your app. Click on Connect now option and your app will be connected to Firebase. After that click on the second option and now your App is connected to Firebase. After connecting your app to Firebase you will get to see the below screen.  

After that verify that dependency for the Firebase Firestore database has been added to our Gradle file. Navigate to app > Gradle Scripts inside that file. Check whether the below dependency is added or not. If the below dependency is not present in your build.gradle file. Add the below dependency in the dependencies section.  

implementation ‘’

implementation ‘com.squareup.picasso:picasso:2.71828’

After adding this dependency sync your project and now we are ready for creating our app. If you want to know more about connecting your app to Firebase. Refer to this article to get in detail about How to add Firebase to Android App.  

Step 3: Working with the AndroidManifest.xml file

For adding data to Firebase we should have to give permissions for accessing the internet. For adding these permissions navigate to the app > AndroidManifest.xml. Inside that file add the below permissions to it.  


<!--Permissions for internet-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Step 4: Working with the activity_main.xml file  

As we are not displaying any UI inside our activity_main.xml. So we are not adding any UI component in our activity_main.xml because we are displaying the data in our custom layout file.  

Step 5: Creating a new layout file for our Bottom Sheet Dialog

As we are displaying one image and text inside our bottom sheet dialog. So we will be building a custom layout for our Bottom Sheet Dialog. For creating a new layout file four our bottom sheet dialog box. Navigate to the app > res > layout > Right-click on it > Click on New > layout resource file and name it as bottom_sheet_layout and add below code to it.  


<?xml version="1.0" encoding="utf-8"?>
    <!--ImageView for displaying our image-->
        android:padding="5dp" />
    <!--Text view for displaying a heading text-->
        android:text="Message one"
        android:textStyle="bold" />
    <!--Text View for displaying description text-->
        android:text="Message Two"
        android:textSize="12sp" />

Step 6: Adding a Bottom Sheet style to our styles.xml file

Navigate to the app > res > values > themes.xml file and add the below code to it in the resources file. 


<style name="BottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
        <item name="bottomSheetStyle">@style/BottomSheetStyle</item>
   <style name="BottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
        <item name="android:background">@android:color/transparent</item>

Step 7: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.squareup.picasso.Picasso;
public class MainActivity extends AppCompatActivity {
    // creating a variable for our firebase
    // firestore and relative layout of bottom sheet.
    FirebaseFirestore db;
    RelativeLayout bottomSheetRL;
    protected void onCreate(Bundle savedInstanceState) {
        // initializing our variables.
        db = FirebaseFirestore.getInstance();
        bottomSheetRL = findViewById(;
        // calling method to
        // display bottom sheet.
    private void displayBottomSheet() {
        // creating a variable for our bottom sheet dialog.
        final BottomSheetDialog bottomSheetTeachersDialog = new BottomSheetDialog(MainActivity.this,;
        // passing a layout file for our bottom sheet dialog.
        View layout = LayoutInflater.from(MainActivity.this).inflate(R.layout.bottom_sheet_layout, bottomSheetRL);
        // passing our layout file to our bottom sheet dialog.
        // below line is to set our bottom sheet dialog as cancelable.
        // below line is to set our bottom sheet cancelable.
        // below line is to display our bottom sheet dialog.;
        // initializing our text views and image views.
        ImageView imageIV = layout.findViewById(;
        TextView textOneTV = layout.findViewById(;
        TextView textTwoTV = layout.findViewById(;
        // creating a variable for document reference.
        DocumentReference documentReference = db.collection("BottomSheetDIalog").document("Data");
        // adding snapshot listener to our document reference.
        documentReference.addSnapshotListener(new EventListener<DocumentSnapshot>() {
            public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
                // inside the on event method.
                if (error != null) {
                    // this method is called when error is not null
                    // and we get any error
                    // in this case we are displaying an error message.
                    Toast.makeText(MainActivity.this, "Error found is " + error, Toast.LENGTH_SHORT).show();
                if (value != null && value.exists()) {
                    // if the value from firestore is not null then we are
                    // getting our data and setting that data to our text view.
                    // after getting the value from firebase firestore
                    // we are setting it to our text view and image view.

Step 8: Adding the data to Firebase Firestore Console in Android

After adding this code go to this link to open Firebase. After clicking on this link you will get to see the below page and on this page Click on Go to Console option in the top right corner.  

After clicking on this screen you will get to see the below screen with your all project inside that select your project.  

Inside that screen click n Firebase Firestore Database in the left window.  

After clicking on Create Database option you will get to see the below screen.  

Inside this screen, we have to select the Start in test mode option. We are using test mode because we are not setting authentication inside our app. So we are selecting Start in test mode. After selecting on test mode click on the Next option and you will get to see the below screen.  

Inside this screen, we just have to click on Enable button to enable our Firebase Firestore database. After completing this process we have to add data to Firebase Firestore in Android. For adding new data. Click on Start Collection Option, then specify collection Name as “BottomSheetDIalog” and after that click on Next, after that, specify Document ID Name as “Data“. Inside the Field section creates three fields as “textOne“, “textTwo“, and “Image” and pass values to it. After adding values to it and click on save and now run your application.  


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads