如何在Arraylist数据中检索Firebase json ArrayList并将其存储在Arraylist中以在以后的Textview中显示 [英] how to retrieve Firebase json ArrayList inside Arraylist data and store it in Arraylist for display in Textview later
问题描述
我想从火力库中检索数据,以便稍后在文本视图"中显示.但数据快照并没有使所有键和值(即date,month,year)仅达到date.我需要在单个文本视图中约会月份和年份.为了计时,我在Fire-base中将数据作为String插入.
I want to retrieve data from fire-base to display later in Text View. but Data-snapshot is not getting all the key and value(i.e. date,month,year) only reaching to date . i need to date month and year in single Text View..
for timing i insert data as String in fire-base..
我确实尝试将日期值添加到Array-list中,但显示为空.当我检查调试器时.我对调试了解得很少.
i did tried to add date value to Array-list but it showing null. when i check in debugger. i know less about debug.
问题在第二个FOR循环中
Problem is in Second FOR loop
我还需要显示帐户和金额.在列表视图中的日期(完成日期),我需要显示的帐户和金额
i need to display account and amount also. In list view date(complete date) ,account and amount i need to display
ArrayList<String> account;
ArrayList<String> amount;
ArrayList<ArrayList<String>> datedata;
final DateDataHelper dateDataHelper = new DateDataHelper(AccountBillList.this, date, month, year);
myRef = database.getReference("purchasebill");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
billlistHelper = ds.getValue(BilllistHelper.class);
assert billlistHelper != null;
account.add(billlistHelper.getAccount());
amount.add(billlistHelper.getAmount());
for (DataSnapshot dd : ds.child("datedata").getChildren(){
dateDataHelper = dd.getValue(DateDataHelper.class);
date.add(dateDataHelper.getDate());
month.add(dateDataHelper.getMonth());
year.add(dateDataHelper.getYear());
}
intendby.add(billlistHelper.getIntendby());
vendorname.add(billlistHelper.getVendorName());
}
billListAdapter.notifyDataSetChanged();
}
class DateDataHelper {
private String date;
private String month;
private String year;
public DateDataHelper(AccountBillList accountBillList, ArrayList<String> date, ArrayList<String> month, ArrayList<String> year) {
}
public DateDataHelper(String date, String month, String year) {
this.date = date;
this.month = month;
this.year = year;
}
// getter and setter are there over here
}
推荐答案
您正在引用节点 purchasebill
,然后在 purchasebill
的直接子代内循环是 gameworld
和 datamination
.
You are referencing the node purchasebill
, and then you are looping inside the direct children of purchasebill
which are gameworld
and datamination
.
要解决您的问题,您可以添加对子 datamination
的引用,这样它就不会在 gameworld
内部循环,因此您可以执行以下操作:
To solve your problem, you can add a reference to child datamination
thus it won't loop inside gameworld
, so you can do the following:
myRef.child("datamination").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
billlistHelper = dataSnapshot.getValue(BilllistHelper.class);
assert billlistHelper != null;
account.add(billlistHelper.getAccount());
amount.add(billlistHelper.getAmount());
for (DataSnapshot dd : dataSnapshot.child("datedata").getChildren(){
dateDataHelper = dd.getValue(DateDataHelper.class);
date.add(dateDataHelper.getDate());
month.add(dateDataHelper.getMonth());
year.add(dateDataHelper.getYear());
}
intendby.add(billlistHelper.getIntendby());
vendorname.add(billlistHelper.getVendorName());
}
billListAdapter.notifyDataSetChanged();
}
这篇关于如何在Arraylist数据中检索Firebase json ArrayList并将其存储在Arraylist中以在以后的Textview中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!