1 回答

TA貢獻(xiàn)1848條經(jīng)驗 獲得超6個贊
要解決此問題,請使用以下代碼行:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference subjectsRef = rootRef.collection("subjects");
Spinner spinner = (Spinner) findViewById(R.id.spinner);
List<String> subjects = new ArrayList<>();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, subjects);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
subjectsRefRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
String subject = document.getString("name");
subjects.add(subject);
}
adapter.notifyDataSetChanged();
}
}
});
結(jié)果將是一個包含 2 個項目的微調(diào)器:
Android
Java
添加回答
舉報