Skip to content Skip to sidebar Skip to footer

Arraylist Always Loaded With User Info From Firebase Database Regardless Of Which User Is Signed In?

In showdata method witch load FirebaseUser info when I run the app and signed in with any user , arrayList in the method is always loaded with User_03 info , debugging show that:

Solution 1:

This is happening because you are have declared the ArrayList<String> arrayList=new ArrayList<>(); inside the for loop. This means that you are creating a new instance of ArrayList class every time you iterate.

In order to solve this, just move the decration outside for loop like this:

privatevoidshowData(DataSnapshot dataSnapshot) {
  ArrayList<String> arrayList=new ArrayList<>(); //Moved outsidefor(DataSnapshot ds : dataSnapshot.getChildren()){

      uInfo.setName(ds.getValue(UserInformations.class).getName());
      uInfo.setEmail(ds.getValue(UserInformations.class).getEmail()); 
      uInfo.setPhone_num(ds.getValue(UserInformations.class).getPhone_num());

      int listSize = arrayList.size();
      arrayList.add(uInfo.getName());
      arrayList.add(uInfo.getEmail());
      arrayList.add(uInfo.getPhone_num()); 
      ArrayAdapter<String> adapter =new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,arrayList);
      userInfolist.setAdapter(adapter);
      toastMassege("its Done ");
  }
}

Post a Comment for "Arraylist Always Loaded With User Info From Firebase Database Regardless Of Which User Is Signed In?"