0

When I run my application, the RecyclerView is always shown blank in the activity. I did code with the normal RecyclerView as well firebaseRecyclerOptions helps with FirebaseAdapter, but lists not showing any data. The data is available on both Realtime Database and Cloud FireStore, but I don't get any data in RecyclerView.

Adapter class

public class FeedsAdapter  extends FirestoreRecyclerAdapter <Fmodel,FeedsAdapter.myFeedViewHolder> {

    public FeedsAdapter(@NonNull FirestoreRecyclerOptions <Fmodel> options) {
        super ( options );
    }

    @Override
    protected void onBindViewHolder(@NonNull myFeedViewHolder holder, int position, @NonNull Fmodel model) {
        holder.name.setText ( model.getFname () );
        holder.mobile.setText ( model.getFmobile () );
        holder.address.setText ( model.getFaddress ());
        holder.message.setText ( model.getFmessage ());
    }
    @NonNull
    @Override
    public myFeedViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from ( parent.getContext () ).inflate ( R.layout.feedbacks,parent,false );

        return new myFeedViewHolder ( view );
    }

    class myFeedViewHolder extends RecyclerView.ViewHolder{

        TextView name,mobile,address,message;

        public myFeedViewHolder(@NonNull View itemView) {
            super ( itemView );
            name = itemView.findViewById ( R.id.name );
            mobile = itemView.findViewById ( R.id.mobile );
            address = itemView.findViewById ( R.id.address );
            message = itemView.findViewById ( R.id.messege );
        }
    }
}

Activity.xml

 public class FeedsActivity extends AppCompatActivity {

    private FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance (  );
    private CollectionReference collectionReference = firebaseFirestore.collection ( "FeedBacks" );
    private  FeedsAdapter feedsAdapter;

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

        setUpRecyclerView();
  }
    
private void setUpRecyclerView() {
        Query query = collectionReference.orderBy ( "Fname", Query.Direction.ASCENDING );
       FirestoreRecyclerOptions <Fmodel> options = new FirestoreRecyclerOptions.Builder<Fmodel>().setQuery ( query,Fmodel.class ).build ();
        feedsAdapter = new FeedsAdapter ( options );

        feedRecyclerView = (RecyclerView) findViewById ( R.id.feedrecycler );
        feedRecyclerView.setHasFixedSize ( true );
        feedRecyclerView.setLayoutManager ( new LinearLayoutManager ( this ) );
        feedRecyclerView.setAdapter ( feedsAdapter);
    }

    @Override
    protected void onStart() {
        super.onStart ( );
        feedsAdapter.startListening ();
        Toast.makeText ( this, "fetch on", Toast.LENGTH_SHORT ).show ( );

    }

    @Override
    protected void onStop() {
        super.onStop ( );
        feedsAdapter.stopListening ();
        Toast.makeText ( this, "fetch off", Toast.LENGTH_SHORT ).show ( );
    }
}

model class

  package gk.com.Model;

public class Fmodel {


    private String fname;
    private String faddress;
    private String fmobile;
    private String fmessage;


    public Fmodel() {
    }

    public Fmodel(String fname, String faddress, String fmobile, String fmessage) {
        this.fname = fname;
        this.faddress = faddress;
        this.fmobile = fmobile;
        this.fmessage = fmessage;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getFaddress() {
        return faddress;
    }

    public void setFaddress(String faddress) {
        this.faddress = faddress;
    }

    public String getFmobile() {
        return fmobile;
    }

    public void setFmobile(String fmobile) {
        this.fmobile = fmobile;
    }

    public String getFmessage() {
        return fmessage;
    }

    public void setFmessage(String fmessage) {
        this.fmessage = fmessage;
    }
}
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Somesh
  • 23
  • 7

1 Answers1

1

You are getting a "blank" activity most likely because of the following lines of code:

Query query = collectionReference.orderBy ( "Fname", Query.Direction.ASCENDING );

Meaning that you are trying to query the FeedBacks collection and order the results according to the Fname property. That line of code makes me think that in your database you have the fname property that starts with an upper case, which is not correct since the fname property in your Fmodel class starts with a lower case. To make it work, both properties must match. To solve this, please check my answer from the following post:

how to read firestore sub-collection and pass it to FirestoreRecyclerOptions

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • it's not helped me. I make changes after also recycler is blank. even I delete this query line for ascending list and pass a query as CollectionReference object. – Somesh Aug 14 '20 at 11:30
  • my problem was solved thank you @Alex Mamo, I had a mistake in my row_item XML file, thanks again. – Somesh Aug 14 '20 at 11:56
  • If you have done the changes suggested in the answer, indeed it solved the problem. The fact that you also had an issue in the .XML file is not related to the initial problem. – Alex Mamo Aug 14 '20 at 12:24