how to retrieve Firebase json ArrayList inside Arraylist data and store it in Arraylist for display in Textview later

被刻印的时光 ゝ 提交于 2019-12-24 20:11:50

问题



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..

i did tried to add date value to Array-list but it showing null. when i check in debugger. i know less about debug.

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
}

回答1:


You are referencing the node purchasebill, and then you are looping inside the direct children of purchasebill which are gameworld and datamination.

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();

} 


来源:https://stackoverflow.com/questions/55906866/how-to-retrieve-firebase-json-arraylist-inside-arraylist-data-and-store-it-in-ar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!