[英]How to retrieve date and time in a RecyclerView from FirebaseFirestore if i have stored time as ServerValue.TIMESTAMP in the database
[英]How to retrieve arrays from FirebaseFirestore using Collections?
db.collection("PublicFormDetails")
.whereEqualTo("Topic Name",message)
.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful())
{
for (QueryDocumentSnapshot snapshot : Objects.requireNonNull(task.getResult())) {
String value1 = snapshot.getString("QuestionName");
Toast.makeText(PublicVote.this, value1, Toast.LENGTH_SHORT).show();
q_tv1.setText("Question: "+value1);
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(PublicVote.this,e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
現在在這里我想檢索以數組形式保存的選項的描述和編號,我上面的代碼也打印數據的其他詳細信息,關於選擇的主題名稱,因此我使用了 whereEqualTo("Topic名稱”,消息)作為我的查詢(其中消息是我選擇的主題)。 現在如何在此檢索描述和選項編號。 我不能使用 DocumentReference,因為那樣我就不能使用 whereEqualsTo。 請幫忙!!!
要獲取這兩個 araay 的內容,請在 for 循環中添加以下兩行代碼:
List<String> description = (List<String>) snapshot.get("Description");
List<String> noOfOptions = (List<String>) snapshot.get("Np. of Options");
在這一行之后:
q_tv1.setText("Question: "+value1);
如果您需要這些 arrays 中的每個元素,請為每個列表創建一個 for 循環並獲取相應的數據。
logcat 中的結果將是:
Hey
What's up?
對於第一個數組,並且:
123
456
對於第二個數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.