我想将数据集存储到从Firestore中提取数据的2D arraylist中。 这是数据库代码。
db.collection("Reminder").orderBy("time").get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()) {
List<DocumentSnapshot> list = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot d : list) {
dbReminder p = d.toObject(dbReminder.class);
p.setId(d.getId());
remtasklist.add(p);
sTime = p.getTime();
sLoc = p.getInLocation();
sTitle = p.getTitle();
ListofInfo();
}
}
}
});
但是我试图在for循环内执行for循环,它抛出了'java.lang.IndexOutOfBoundsException',所以我只是这样做了
ArrayList.get(0).add(sTime);
ArrayList.get(0).add(sLoc);
ArrayList.get(0).add(sTitle);
我明白了
I/System.out: [[09:55, Bedroom, drink water, 11:05, Kitchen, Feed the cat, 11:15, Kitchen, Prepare supper, 15:55, Kitchen, Eat book, 16:40, Kitchen, go to store, 17:39, Bedroom, get home]]
我想要的是
[[09:55, Bedroom, drink water], [11:05, Kitchen, Feed the cat], [11:15, Kitchen, Prepare supper], [15:55, Kitchen, Eat book], [16:40, Kitchen, go to store], [17:39, Bedroom, get home]]