[英]How to get a field and update a textview from firestore?
我試圖從 Firestore 獲取值,但每次都為 null。 有人能告訴我我做錯了什么嗎? 這是我的 Firestore 集合和文檔。
DocumentReference docRef = dbase.collection("newsImage").document("cqmpNF45IZsHDSx9hSuq");
colref.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull @NotNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
str = document.getString("imgNews");
tv.setText(str);
} else
Log.d("docv", "No such document");
} else
Log.d("docv", "get failed with ", task.getException());
}
});
問題很可能來自以下代碼行:
String newsText= ipustr;
tv.setText(sectorText);
您嘗試分配不是來自數據庫的值的地方。 所以很可能你應該做這樣的事情:
str = document.getString("imgNews");
tv.setText(str);
甚至是簡單的:
tv.setText(document.getString("imgNews"));
編輯:
提交的名稱不正確,請使用:
tv.setText(document.getString("imgnews"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.