-1

I am developing a app which needs to fetch data from firebase into a recycler view but it is not doing so. the app runs fine but does not show anything in recycler view portion.

MainArea.java(onCreate)

protected void onCreate( Bundle savedInstanceState ) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_rating);
        Email=(TextView)findViewById(R.id.Email);
        Fullname=(TextView)findViewById(R.id.Name);
        City=(TextView)findViewById(R.id.City);
        Address=(TextView)findViewById(R.id.Address);
        rating=(TextView)findViewById(R.id.Rating);
        int s=getIntent().getIntExtra("position",0);
        DatabaseReference ref=MainArea.FBRA.getRef(s);
        ss=ref.getKey();
        DatabaseReference ref2= FirebaseDatabase.getInstance().getReference().child("Users").child(ss);
        ref2.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange( DataSnapshot dataSnapshot ) {
                  email=dataSnapshot.child("email").getValue().toString();
                  fullname=dataSnapshot.child("fullname").getValue().toString();
                  city=dataSnapshot.child("city").getValue().toString();
                  address=dataSnapshot.child("address").getValue().toString();
                  Totalrating=dataSnapshot.child("TotalRating").getValue().toString();
                    rating.setText(Totalrating);
                    Email.setText(email);
                    Fullname.setText(fullname);
                    City.setText(city);
                    Address.setText(address);

            }

            @Override
            public void onCancelled( DatabaseError databaseError ) {

            }
        });
        myRef2=FirebaseDatabase.getInstance().getReference("RatingPosts").child(ss);
        Rview=(RecyclerView)findViewById(R.id.recycler);
        Rview.setHasFixedSize(true);
        Rview.setLayoutManager(new LinearLayoutManager(DisplayRating.this));
        FirebaseRecyclerAdapter<dataget,ViewHolder2> Fbra=new FirebaseRecyclerAdapter<dataget, ViewHolder2>(
                dataget.class,
                R.layout.cardr2,
                ViewHolder2.class,
                myRef2
        ) {
            @Override
            protected void populateViewHolder( ViewHolder2 viewHolder, dataget model, int position ) {
                    viewHolder.setAddress(model.getAddress());
                    viewHolder.setPicture(model.getPicture());
                    viewHolder.setRating(model.getRating());

            }
        };
        Rview.setAdapter(Fbra);
     }

ViewHolder

public  static class ViewHolder2 extends RecyclerView.ViewHolder
     {
         View mView;
         Context ctx;
         public ViewHolder2( View itemView ) {
             super(itemView);
             mView=itemView;
             ctx=itemView.getContext();
         }


         public void setAddress( String address ) {
            TextView Add=(TextView)mView.findViewById(R.id.add);
            Add.setText(address);
         }

         public void setPicture( String picture ) {
             ImageView img=(ImageView)mView.findViewById(R.id.img);
             Picasso.with(ctx).load(picture).into(img);
         }

         public void setRating( String rating ) {
                TextView rate=(TextView)mView.findViewById(R.id.ratee);
                rate.setText(rating);
         }
     }

dataget.java

package com.hitachiapp.hitachi.hitachiapp;

/** * Created by Mohit Gupta on 23-05-2018. */

public class dataget {

String Address,Picture,Rating;

public dataget( String address, String picture, String rating ) {
    Address = address;
    Picture = picture;
    Rating = rating;
}

public dataget() {
}

public String getAddress() {
    return Address;
}

public void setAddress( String address ) {
    Address = address;
}

public String getPicture() {
    return Picture;
}

public void setPicture( String picture ) {
    Picture = picture;
}

public String getRating() {
    return Rating;
}

public void setRating( String rating ) {
    Rating = rating;
}

}

firebase Structure this is the image

Lucem
  • 2,912
  • 3
  • 20
  • 33
Mohit Gupta
  • 41
  • 1
  • 7

1 Answers1

0

1 - Ensure that you add the permissions line in the manifest file

<uses-permission android:name="android.permission.INTERNET" />

2 - Check your DatabaseReference. Try using FirebaseDatabase.getInstance().getReference("RatingPosts") to confirm is the link is valid or Log the data in the logcat

3 - Ensure that your data model is your database data model. (Your screenshot indicate that the children have more children and your data model shows data types)

4 - Make sure recycler.setAdapter(adapter); is called after adapter

5 - Ensure that you call recycler.setLayoutManager(layout); before number 4

Your code is not sufficient to debug without the log but this are the common mistakes that people do while using firebase.

Lucem
  • 2,912
  • 3
  • 20
  • 33
  • @MohitGupta Your code is not sufficient to debug without the log but this are the common mistakes that people do while using firebase. – Lucem May 24 '18 at 05:44
  • I tried the above solution No 2 When i intialize database reference to as in 2 some blank rows are shown But when i intialize it to FirebaseDatabase.getInstance().getReference("RatingPosts").child(ss); Nothing comes.. ss=key i.e B2WKQY... what to do now @Lucem – Mohit Gupta May 24 '18 at 07:49
  • Please help @Lucem – Mohit Gupta May 24 '18 at 08:02
  • the only way i can help you is if you clean up your code, Test it on a separate activity with independent values @MohitGupta. Would you like me to inspect it for you? – Lucem May 24 '18 at 14:26