我希望在我的"notes"
活动的列表视图中检索Firebase数据库数据。我写了一些代码,但没有显示值。
private void viewAllNotes() {
databaseReference = FirebaseDatabase.getInstance().getReference("Notes");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot postSnapshot : dataSnapshot.getChildren()){
spinnerData spinnerData = postSnapshot.getValue(spinnerData.class);
NotesList.add(spinnerData);
}
String [] Notes = new String[NotesList.size()];
for(int i=0;i<Notes.length;i++){
Notes[i] = NotesList.get(i).getName();
}
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,Notes){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView myText = (TextView) view.findViewById(android.R.id.text1);
myText.setTextColor(Color.BLACK);
return view;
}
};
listViewNotes.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
我在firebase中的数据库就像
Spinnerdata ----> -Lnansd3ur3ufbu3bu3 ------> name: tybsc com sci (etc)'
我希望它们在活动列表视图中