Firebase Realtime database getvalue() not mapping the object

后端 未结 4 802
长发绾君心
长发绾君心 2021-01-25 00:41

This is my firebase chat structure(see image below). I want to get only amitpal_name value not the others but this method fetching me all the values
I had also use this

4条回答
  •  一向
    一向 (楼主)
    2021-01-25 01:10

    change your below line

    String chatis=(String) ((DataSnapshot)iterator.next()).getValue();
    

    to

    String chatis=((DataSnapshot)iterator.next()).getValue().toString();
    

    Updated method below

        @Override
        public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
    Log.e( "OUTER ADDED IS-" , dataSnapshot.getValue().toString());
           Iterator iterator=dataSnapshot.getChildren().iterator();
            while (iterator.hasNext()){
            DataSnapshot local = (DataSnapshot) iterator.next();
                String chatis=local.getValue().toString();
                Log.e( "Inner ADDED IS-" , chatis);
            }
    
        }
    

    EDIT

    also below line as well after the reference initialization

    dbreference.keepSynced(true);
    

提交回复
热议问题