reference.child("category").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.d("Firebase",dataSnapshot.getValue(String.class)+" Key is "+Integer.parseInt(dataSnapshot.getKey()));
cat.add(Integer.parseInt(dataSnapshot.getKey()),dataSnapshot.getValue(String.class));
if(Integer.parseInt(dataSnapshot.getKey())==0) {
adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.support_simple_spinner_dropdown_item, cat);
catList.setAdapter(adapter);
}
else {
adapter.notifyDataSetChanged();
}
}
我想在列表视图中显示该类别。但是当我执行此代码时,只显示了第一个类别,但在日志中显示了类别(有两个类别)。
答案 0 :(得分:1)
从循环中取出以下代码:
if(Integer.parseInt(dataSnapshot.getKey())==0) {
adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.support_simple_spinner_dropdown_item, cat);
catList.setAdapter(adapter);
}
希望它有所帮助。