0

I am trying to have a sectioned recyclerview reading from firebase like this:https://stackoverflow.com/questions/36322058/recyclerview-sections-and-data-from-firebase but I really have less knowledge on it, I tried looking up on it here: Sectioned Recyclerview and here: which is where I go the Image above but I'm more confused than before, if anyone knows a solution to this, please provide it for me or if you have done a similar thing, please help.

This is my code if it will be of any help and I'm using FirebaseRecyclerViewAdapter:

@Override
protected void onStart() {
    super.onStart();

    //Creating an adapter to hold values sequential.
    FirebaseRecyclerAdapter<Book, BooksReadActivity.userBooksViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Book, userBooksViewHolder>(

            Book.class,
            R.layout.book_row,
            BooksReadActivity.userBooksViewHolder.class,
            mQueryCurrentUser

    ) {
        @Override
        protected void populateViewHolder(BooksReadActivity.userBooksViewHolder viewHolder, Book model, final int position) {

            final String book_key = getRef(position).getKey();

            viewHolder.setTitle(model.getTitle());
            viewHolder.setAuthor(model.getAuthor());
            viewHolder.setDescription(model.getDesc());
            viewHolder.setImage(getApplicationContext(), model.getImage());
            viewHolder.setSubmissionDate(model.getSubmissionDate());

            viewHolder.mView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent bookViewIntent = new Intent(getApplicationContext(), ProfileBooksRead.class);
                    bookViewIntent.putExtra("book_id", book_key);
                    startActivity(bookViewIntent);

                }
            });

        }
    };

    //Set the Booklist{@RecylerView} to firebaseRecyclerviewAdapter.
    mBookList.setAdapter(firebaseRecyclerAdapter);

}


public static class userBooksViewHolder extends RecyclerView.ViewHolder {

    DatabaseReference mDattabaseLike;
    FirebaseAuth mAuth;

    TextView book_title;

    ImageButton mLikeBtn;

    View mView;

    public userBooksViewHolder(View itemView) {
        super(itemView);

        mView = itemView;

        book_title = (TextView) mView.findViewById(R.id.book_title);

        mDattabaseLike = FirebaseDatabase.getInstance().getReference().child("Likes");
        mAuth = FirebaseAuth.getInstance();
        mDattabaseLike.keepSynced(true);

    }

    public void setTitle(String title) {
        book_title.setText(title);

    }

    public void setAuthor(String author) {
        TextView book_author = (TextView) mView.findViewById(R.id.book_author);
        book_author.setText(author);

    }

    public void setDescription(String desc) {
        TextView book_desc = (TextView) mView.findViewById(R.id.book_desc);
        book_desc.setText(desc);

    }

    public void setSubmissionDate(String submissionDate) {

        TextView tvSubmissionDate = (TextView) mView.findViewById(R.id.tv_sub_date);
        tvSubmissionDate.setText(submissionDate);

    }

    public void setImage(final Context c, final String image) {
        final ImageView imageView = (ImageView) mView.findViewById(R.id.book_image);
        Picasso.with(c).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(imageView, new Callback() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onError() {

                Picasso.with(c).load(image).into(imageView);

            }
        });

    }
    /*
    * Methods for setting values for displaying{@ends here}
    * */
}
Community
  • 1
  • 1
Zack
  • 472
  • 7
  • 16
  • `FirebaseRecyclerView` is really good library but i think when you come to complex requirement, manually getting data from Firebase and setup your own custom adapter would be better. – Boonya Kitpitak Mar 30 '17 at 09:46
  • So I should change the way I am reading my data from firebase currently? – Zack Mar 30 '17 at 09:58
  • I'm not sure but I would prefer loading needed data into `List` or `ArrayList` then use that data to setup with `RecyclerView` since You have to do sectioning but `FirebaseRecyclerView` may not provided. – Boonya Kitpitak Mar 30 '17 at 10:03
  • I'll try List and see if it works, thanks. – Zack Mar 30 '17 at 12:26
  • i think my answer here will help http://stackoverflow.com/a/43131742/5381331 – Linh Mar 31 '17 at 04:31

0 Answers0