我正在尝试从firebase中读取一个分段的recyclerview,如下所示:但我真的对此知之甚少,我试着在这里查看:Sectioned Recyclerview并在这里:{{3但是我比以前更困惑,如果有人知道解决方法,请为我提供,或者如果你做了类似的事情,请帮助。
这是我的代码,如果它有任何帮助,我使用的是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}
* */
}