为了避免这种情况发生,是的,在这个问题上有类似的问题,但它并不能完全解释我的情况要求我的想法。Android Firebase:如何简单获取某个键下的所有值?
在火力地堡实时数据库,我有一个JSON树看起来是这样的:
users{
userid{
templates{
templateName1{ // example name that the user saves their template as.
// each template is an ArrayList
//templateName1 ArrayList contents
}
templateName2{
//templateName1 ArrayList contents
}
templateName2{
//templateName1 ArrayList contents
}
}
}
}
我需要能够列出每个模板中的“模板”,并在其他时间只需获得的ArrayList特定模板的值。但我似乎无法弄清楚如何做这个简单的事情。
从我GOOGLE了/在文档阅读,我的代码应该是这个样子:
DatabaseReference mTemplateRef = mDatabase.child("users").child(uid).child("templates");
mTemplateRef.addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.getChildren();
// somehow get the values here
}
});
当我调试,并输入表达式数据dataSnapshot.getChildren()我可以看到的内容如预期的那样,但我似乎无法将这些数据输入到我的应用程序中。有任何想法吗?
嗯,我仍然有问题。这将如何让我列出关键“模板”下的所有ArrayLists?也许有每个迭代添加到单独的ArrayList?这是如何将ArrayList设置为模板类的?我也遇到了这个错误:com.google.firebase.database.DatabaseException:无法将类型为java.util.ArrayList的对象转换为com.app.template_editor.template – theRealOne
我要离开以前的评论如果你看到任何明显的东西,但我认为我知道该怎么做,直到放学后才能测试它。我会更新,如果它出来 – theRealOne
所以,现在我做了你说的,但我得到一个错误,我“不能转换类型ArrayList的对象类型模板”与模板是您提供的类。 – theRealOne