【发布时间】:2019-10-18 11:57:40
【问题描述】:
我已经花费了很多时间来寻找如何在里面放置一个数组。我想访问数组的每个元素并将其存储在一个字符串中,例如 String array = ??? (我想得到价值)。
为了进一步理解我的问题。假设我有一个包含所有 id 的数组,我想检查是否存在 id,如果存在,我想让每个元素存储在一个字符串中(每个元素必须在不同的字符串上),以便我以后可以使用它在我的其他活动中。
有没有类似使用for循环的方法?
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DocumentReference docRef = db.collection("Users").document(userId);
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String plan_id = document.get("plan_id").toString();
Log.d(TAG, "***Found field: " + plan_id);
} else {
Log.d(TAG, "***No such document");
}
} else {
Log.d(TAG, "***Get failed with ", task.getException());
}
}
});
我得到以下输出
***Found field: [3bTzKOmIS1zEHprJa1u0, 6nDgyEimKOnoPbZRsbmQ]
【问题讨论】:
-
请将您的数据库结构添加为截图。
标签: java android arrays firebase google-cloud-firestore