我的问题是我试图通过添加firebaselistAdapter方法检索的对象来填充我的arraylist,但它不能,它不会将对象添加到列表中。 这是代码:
comments = new ArrayList<Comment>();
refJ = FirebaseDatabase.getInstance().getReference().child("comments");
commentsAdapter = new FirebaseListAdapter<Comment>(this, Comment.class, R.layout.item_comment, refJ) {
@Override
protected void populateView(View view, Comment j, int position) {
comments.add(j); ((TextView)view.findViewById(R.id.textViewComment)).setText(j.getJ_nom());
Picasso.with(getApplicationContext())
.load(j.getJ_image())
.placeholder(R.drawable.ic_person_outline_black_24dp)
.error(R.drawable.ic_profile)
.resize(300, 250)
.transform(new CircleTransform())
.into((ImageView) view.findViewById(R.id.imageViewComment));
}
};
使用firebaselisAdapter一切正常,它完美展现出来;我的问题是我想在评论的arraylist中添加评论。 我使用此代码来确保评论列表:
Iterator<Comment> it = comments.iterator();
while (it.hasNext()) {
System.out.println("Comment : "+ it.next()+"\n");
}
public class Comment{
private String j_emplacement;
private String j_equipe;
private String j_image;
private String j_nom;
private Long j_numero;
private String j_prenom;
public Comment() {
}
public Comment(String j_emplacement, String j_equipe, String j_image, String j_nom, Long j_numero, String j_prenom) {
this.j_emplacement = j_emplacement;
this.j_equipe = j_equipe;
this.j_image = j_image;
this.j_nom = j_nom;
this.j_numero = j_numero;
this.j_prenom = j_prenom;
}
// getters and setters}
我发现评论列表是空的。 任何帮助,将不胜感激 ,;致谢
答案 0 :(得分:0)
试试这个
List<String> commentKeys=new ArrayList<String>();
DatabaseReference mDatabase=FirebaseDatabase.getInstance().getReference().child("comments").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot snap:dataSnapshot.getChildren()){
commentKeys.add(snap.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});