【发布时间】:2021-01-22 01:13:44
【问题描述】:
我能够在 firebase 集合中获取数据,但它不会在回收站视图中查询该数据。 Recyclerview 不显示任何东西
这是 comment_list 类。
public class comment_list {
public comment_list(String comments) {
this.comments = comments;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
String comments;
}
这是comment_adapter 类
public class comment_adapter extends FirestoreRecyclerAdapter<comment_list, comment_adapter.comment_holder> {
public comment_adapter(@NonNull FirestoreRecyclerOptions<comment_list> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull comment_holder holder, int position, @NonNull comment_list model) {
holder.commment_on_post.setText(model.getComments());
}
@NonNull
@Override
public comment_holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_recycler_dsign, parent, false);
return new comment_holder(v);
}
public class comment_holder extends RecyclerView.ViewHolder{
TextView commment_on_post;
public comment_holder(@NonNull View itemView) {
super(itemView);
commment_on_post = itemView.findViewById(R.id.commenttextview);
}
}
这是评论类。在此我能够在 firebase 集合中获取数据,但不是在回收站视图中查询该数据。
public class Comments extends AppCompatActivity {
ImageView profileimage;
EditText addcommenttext;
TextView postcommenttext;
FirebaseFirestore db;
RecyclerView comment_recycler_view;
comment_adapter adaptercomment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comments);
profileimage = findViewById(R.id.Addcommentprofileimage);
addcommenttext = findViewById(R.id.addcommenttext);
postcommenttext = findViewById(R.id.postcomment);
comment_recycler_view = findViewById(R.id.commentsrecycler);
postcommenttext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (addcommenttext.equals("")) {
Toast.makeText(Comments.this, "Comment can't be empty", Toast.LENGTH_SHORT).show();
} else {
String commentText = addcommenttext.getText().toString();
CollectionReference commentref = FirebaseFirestore.getInstance() .collection("CommentDetails");
commentref.add(new comment_list(commentText));
FirebaseFirestore fbfs = FirebaseFirestore.getInstance();
CollectionReference commentrefs = fbfs.collection("CommentDetails");
Query query = commentrefs;
FirestoreRecyclerOptions<comment_list> options = new FirestoreRecyclerOptions.Builder<comment_list>()
.setQuery(query, comment_list.class)
.build();
adaptercomment = new comment_adapter(options);
comment_recycler_view.setHasFixedSize(true);
comment_recycler_view.setLayoutManager(new LinearLayoutManager(getApplication()));
comment_recycler_view.setAdapter(adaptercomment);
finish();
Toast.makeText(Comments.this, "Commented", Toast.LENGTH_SHORT).show();
}
}
});
}
【问题讨论】:
-
请发布您的数据库结构
-
你数据库中的数据
-
您在 Cloud Firestore 中的平均收藏?
-
请编辑您的问题并将您的数据库结构添加为屏幕截图。请回复@AlexMamo
-
@AlexMamo 我确实请检查
标签: java android database firebase comments