我的应用程序中有很多类别和子类别,所以我从firebase中检索了日期。之后,我尝试将此数据转换为列表的集合以放入我的GUI。
这是我的类别中的示例:
你可以看到我有书类,
0 - >属性此类别和1 - >是子类别
我很困惑如何阅读这些类别和子类别,并将每个类别和子类别放在一个列表中,我可以在那之后轻松使用:)。
Firebase ref =新Firebase(Constants.FIREBASE_URL);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_default, null, false);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Map<String, Object> td = (HashMap<String,Object>) dataSnapshot.getValue();
for (Map.Entry<String, Object> entry : categoriesMap.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
该代码的输出如下:
Key = books,
Value = [{name=books}, {cookbooks={name=CookBooks}, fiction={name=Fiction},
accessories=[{name=Accessories}, {bookcovers={name=BookCovers}, otherbookaccessories={name=OtherBookAccessories}, bookmarks={name=BookMarks},
booklights={name=BookLights}}], nonfiction={name=Nonfiction}, otherbooks=
{name=OtherBooks}, agazine={name=Magazine}, catalogues={name=Catalogues},
childreanyoungadult={name=ChildreanYoungAdult}, audiobooks={name=AudioBooks},
textbookseducation={name=TextBooksEducation}, antiquariancollectible=
{name=AntiquarianCollectible}}]