【发布时间】:2018-09-20 21:11:02
【问题描述】:
我知道有很多类似的问题,但我已经阅读并尝试了所有方法,但仍然无法解决这个问题。我想要实现的是用来自 firebase 的数据填充我的列表视图。我正在关注 youtube 上的教程,但我添加了一些东西,特别是时间戳。错误在我的 for 循环中并说:
类 java.util.Map 有泛型类型参数,请改用 GenericTypeIndicator
这是我的数据库的样子:
我的 Notes.java
public class Notes {
String noteId;
String noteCategory;
String note;
String rating;
public Map timeStamp;
public Notes(){
}
public Notes(String noteId, String noteCategory, String note, String rating, Map timeStamp) {
this.noteId = noteId;
this.noteCategory = noteCategory;
this.note = note;
this.rating = rating;
this.timeStamp = timeStamp;
}
public String getNoteId() {
return noteId;
}
public String getNoteCategory() {
return noteCategory;
}
public String getNote() {
return note;
}
public String getRating() {
return rating;
}
public Map<String,String> getTimeStamp() { return timeStamp;}
}
下面是我的 NoteList.java
@Override
protected void onStart() {
super.onStart();
databaseNotes.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
notesList.clear();
for(DataSnapshot noteSnapshot : dataSnapshot.getChildren()){
Notes notes = noteSnapshot.getValue(Notes.class);
notesList.add(notes);
}
NoteList adapter = new NoteList(MyNotes.this, notesList);
listViewNotes.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
任何建议将不胜感激!提前谢谢你。
编辑:好的,我已经尝试了建议的答案,在我记录地图后,它会在控制台上显示我的数据。但是,如何将我的地图迭代到列表视图中?
Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
【问题讨论】:
-
成员
timeStamp的类型是Map,但它没有指明键和值的类型。它应该类似于Map<String, String> -
是的,我已经通过线程并尝试了一切。它不起作用。 @NileshRathod
-
不适用于我的情况:( @QandilTariq
标签: java android firebase firebase-realtime-database