Failed to show data retrieved from Firebase in RecyclerView

how to retrieve firebase data into recyclerview
how to retrieve firebase data into cardview and recyclerview
firebaserecycleradapter
firebase console
populate recyclerview from firebase
firebase ui recyclerview
how to retrieve image from firebase database in android
firebase recycler options dependency

I believe my recyclerView have successfully retrieve data from firebase because it shows 2 cardView inside my recycler view, which is the same number of data allocated inside my firebase under Menu.

Screenshot of my RecyclerView.

I have 3 classes which are listOnline2, MyAdapter and cMenu. There are an array inside both lisOnline2 and MyAdapter. I use array in listOnline2 store retrieved data from firebase and array in MyAdapter to view data inside cardview. Below are my codings for the class listOnline2.

`DatabaseReference currentUserRef,counterRef, ref;
MyAdapter adapterR;

RecyclerView listOnline21;
ArrayList <cMenu> menu;
private static final String TAG = "listOnline2";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_list_online2 );

    listOnline21= (RecyclerView) findViewById(R.id.listMenu);
    listOnline21.setLayoutManager( new LinearLayoutManager( listOnline2.this ) );
    listOnline21.setHasFixedSize(true);
menu= new ArrayList<cMenu>();


    counterRef= FirebaseDatabase.getInstance().getReference().child( "Menu" ).child( "twRAlXRMSgPkA35nmMoFAuAsTdz1" );
    Log.d( TAG, "Clicked ID: "+idd );
    currentUserRef=FirebaseDatabase.getInstance().getReference("Menu").child( FirebaseAuth.getInstance().getCurrentUser().getUid() );

    counterRef.addValueEventListener( new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren()){

                cMenu p=dataSnapshot1.getValue(cMenu.class);
                menu.add(p);

            }
            Log.d( TAG, "Data of array: "+menu );
            adapterR=new MyAdapter( listOnline2.this, menu );
            listOnline21.setAdapter( adapterR );
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            Toast.makeText(listOnline2.this, "Opsss.... Something is wrong", Toast.LENGTH_SHORT).show();
        }
    } );

    Toolbar toolbar=findViewById(R.id.toolbar);
    toolbar.setTitle("Food Ordering Delivery System");
    setSupportActionBar(toolbar);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater= getMenuInflater();
    inflater.inflate( R.menu.main_menu,menu );
    return true;
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()){
        case R.id.action_cart:
            Intent toCart=new Intent( listOnline2.this, Cart.class );
            startActivity( toCart );
            break;

        case R.id.action_logout:
            Intent toLogin=new Intent( listOnline2.this, LoginActivity.class );
            startActivity( toLogin );

            break;
    }
    return super.onOptionsItemSelected( item );
}`

Meanwhile, below are my codes in MyAdapter class

DatabaseReference currentUserRef,counterRef;
MyAdapter adapterR;

RecyclerView listOnline21;
ArrayList <cMenu> menu;
private static final String TAG = "listOnline2";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_list_online2 );

    listOnline21= (RecyclerView) findViewById(R.id.listMenu);
    listOnline21.setLayoutManager( new LinearLayoutManager( listOnline2.this ) );
    listOnline21.setHasFixedSize(true);
       menu= new ArrayList<cMenu>();


    counterRef= FirebaseDatabase.getInstance().getReference().child( "Menu" ).child( "twRAlXRMSgPkA35nmMoFAuAsTdz1" );
    Log.d( TAG, "Clicked ID: "+idd );
    currentUserRef=FirebaseDatabase.getInstance().getReference("Menu").child( FirebaseAuth.getInstance().getCurrentUser().getUid() );

    counterRef.addValueEventListener( new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren()){

                cMenu p=dataSnapshot1.getValue(cMenu.class);
                menu.add(p);

            }
            Log.d( TAG, "Data of array: "+menu );
            adapterR=new MyAdapter( listOnline2.this, menu );
            listOnline21.setAdapter( adapterR );
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            Toast.makeText(listOnline2.this, "Opsss.... Something is wrong", Toast.LENGTH_SHORT).show();
        }
    } );

    Toolbar toolbar=findViewById(R.id.toolbar);
    toolbar.setTitle("Food Ordering Delivery System");
    setSupportActionBar(toolbar);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater= getMenuInflater();
    inflater.inflate( R.menu.main_menu,menu );
    return true;
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()){
        case R.id.action_cart:
            Intent toCart=new Intent( listOnline2.this, Cart.class );
            startActivity( toCart );
            break;

        case R.id.action_logout:
            Intent toLogin=new Intent( listOnline2.this, LoginActivity.class );
            startActivity( toLogin );

            break;
    }
    return super.onOptionsItemSelected( item );
}

And the last class is cMenu is as follows:

private String fName, fDesc, fImage, fQuantity, fPrice, fId;

public cMenu() {
}

public cMenu(String fName, String fDesc, String fImage, String fQuantity, String fPrice, String fId) {
    this.fName = fName;
    this.fDesc = fDesc;
    this.fImage = fImage;
    this.fQuantity = fQuantity;
    this.fPrice = fPrice;
    this.fId = fId;
}

public String getfName() {
    return fName;
}

public void setfName(String fName) {
    this.fName = fName;
}

public String getfDesc() {
    return fDesc;
}

public void setfDesc(String fDesc) {
    this.fDesc = fDesc;
}

public String getfImage() {
    return fImage;
}

public void setfImage(String fImage) {
    this.fImage = fImage;
}

public String getfQuantity() {
    return fQuantity;
}

public void setfQuantity(String fQuantity) {
    this.fQuantity = fQuantity;
}

public String getfPrice() {
    return fPrice;
}

public void setfPrice(String fPrice) {
    this.fPrice = fPrice;
}

public String getfId() {
    return fId;
}

public void setfId(String fId) {
    this.fId = fId;
}

What can I do to display data from the Array that I stored data retrieved from my Firebase? Please give me a suggestion because I spend 2 days starring at these codes. Thank you in advance!

int id=FirebaseAuth.getInstance.getCurrentUser.getUid(); currentUserRef=FirebaseDatabase.getInstance().getReference().child("Menu").child(id);

How to Retrieve Images & Text from Firebase to Recyclerview , Displaying lists of data using a RecyclerView. To retrieve this data without FirebaseUI, you might use addChildEventListener to listen for live updates: necessary to read the data before calling startListening() or your query will fail. Contents in this project Show Firebase database data into RecyclerView ListView Tutorial : 1. Read our previous tutorial Inserting data into Firebase real time database. Because using this tutorial you can know how to insert data into firebase database using android application and how to configure firebase project in android studio properly. 2.

I solved it! I change 3 variable from cMenu class.

fName to menuName

fDesc to foodDescription

fPrice to price

The reason why those variable need to change in order to view data from firebase is that variables from the setter getter class need to have the same variable name as in the database. You can view my database screenshot in the question section. Thank you for your efforts!

FirebaseUI for Realtime Database, Displaying lists of data using a RecyclerView. To retrieve this data without FirebaseUI, you might use addSnapshotListener to listen for live query updates: 2. Android Firebase – RecyclerView Multiple Fields. Android Firebase Database RecyclerView Tutorial This is an android firebase database RecyclerView tutorial. How to save data to firebase,retrieve then show that data in a custom RecyclerView. This time around we use multiple fields as opposed to single field like we did in the previous

put in OnCreate method

adapterR=new MyAdapter( listOnline2.this, menu );
listOnline21.setAdapter( adapterR );

Use this line onDataChange method

adapterR.notifyDataSetChanged();

FirebaseUI for Cloud Firestore, Retrieve Data from Firebase and Display in ListView, Subscribe for More Videos have one item to try and read back it works if I try to get all three items the app fails. Contents in this project Show Firebase database data into RecyclerView� Hello, Everyone In this Video Tutorial, I have shown you how can we use a recycler view to show data from firebase real-time database into the android application. This example video tutorial

ListView making in Firebase Android, Read and write data to Firestore from an Android app; Listen to changes in Firestore data in realtime; Use Firebase Authentication and security rules to secure� In order to address this, we'll use FirebaseUI's FirebaseRecyclerAdapter to map our Restaurant data from Firebase to Android. Firebase RecyclerView Setup. First off, take a moment to glance over the general FirebaseUI's README and the firebase-ui-database docs. To install this tool we'll add the following to our app's dependencies:

Cloud Firestore Android Codelab, When I execute my code it is not displaying any item. It is working perfectly fine import com.google.firebase.database.DatabaseReference; Android Firebase 01 : RecyclerView - Retrieve Text and Images with Picasso Using Recyclerview to show data from Firebase Database - Duration: 40:33. Retrieving User Data from Firebase

RecyclerView using FirebaseRecyclerAdapter is not displaying , If you support Google Sign-in and haven't yet specified your app's SHA-1 fingerprint, do so from the Settings page of the Firebase console. See Authenticating� Firebase data is retrieved by either a one time call to GetValueAsync() or attaching to an event on a FirebaseDatabase reference. The event listener is called once for the initial state of the data and again anytime the data changes.

Comments
  • Sorry, under my menu its not the current user's id. Thanks for trying!
  • I think recyclerView can't notifyDataSetChanged. Only adapters can. Correct me if I am wrong.
  • yes sorry my bad only adapter can notifyDataSetChanged