我從數據庫中獲取價格 if (dataSnapshot.child("Price").getValue() != null) { Price = String.valueOf(dataSnapshot.child("Price").getValue().toString()); Log.d("Reservation", "c" + Price); }價格的價值根據服務而增加。如何將這些價格值添加到數組中{20, 30 , 50}
2 回答

至尊寶的傳說
TA貢獻1789條經驗 獲得超10個贊
據我了解,您正在 for 循環或某些事件調用中執行上述代碼邏輯。在這種情況下,您應該列出一個清單并將每個價格保留在該清單中
聲明ArrayList一些循環或方法之外的地方
ArrayList<String> priceList = new ArrayList();
if (dataSnapshot.child("Price").getValue() != null) {
priceList.add(dataSnapshot.child("Price").getValue().toString());
}
現在您已經有了priceList{20,10,30} 等值,并且可以在任何地方使用它。
添加回答
舉報
0/150
提交
取消