![](/img/trans.png)
[英]Android && Firebase realtime database data retrieving and writing
[英]Android Studio Realtime Database Retrieving Data for RecylerView
我正在嘗試為我的 recView 從數據庫中檢索數據。
我想獲取 A 子節點(a、b、c)、B 子節點並將其添加到我的模型中。
但我不能得到所有。 我需要使用 model.add(modela) 或 model.add(modelb) 但我希望所有模型都添加我的列表。 我該怎么辦?
這是我的代碼;
List<Model> model= new ArrayList<>();
FirebaseDatabase.getInstance()
.getReference(path_road).child(AAA).child("AA")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {
for (DataSnapshot AsnapShot : snapshot.getChildren()) {
Model modela = AsnapShot.child("A").getValue( class );
Model modelab= AsnapShot.child("B").getValue( class );
model.add(i want to add here childA and childB);
如果名稱始終為A
和B
,則可以創建如下所示的父模型類(例如ParentModel
):
public class ParentModel {
@PropertyName("A")
public Model modela;
@PropertyName("B")
public Model modelb;
}
以上是可以工作的最小類,但您當然也可以添加 getter 和 setter。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.