manisha
12/9/2018 - 11:59 PM

Read from firebase

mRootRef.child("Person").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                persons.clear();

                for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                    if (postSnapshot != null) {
                        Person person = new Person();
                        person.setName(postSnapshot.child("name").getValue().toString());
                        String budget=postSnapshot.child("totalBudget").getValue().toString();
                        //Log.d("hello", Integer.valueOf(budget));
                        person.setTotalBudget(Integer.valueOf(budget) );
                        String bought=postSnapshot.child("totalBought").getValue().toString();
                        person.setTotalBought(Integer.valueOf(bought));
                        String gift=postSnapshot.child("totalBought").getValue().toString();
                        person.setGiftCount(Integer.valueOf(gift));
                        persons.add(person);
                    }
                }
                personsAdapter = new PersonsAdapter(ChristmasListActivity.this, R.layout.person_item, persons);
                listView.setAdapter(personsAdapter);
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                Person person=persons.get(position);
                Log.d("hello1", person.getTotalBudget()+"");
                Intent intent=new Intent(ChristmasListActivity.this,PersonGiftsActivity.class);
                Bundle bundle=new Bundle();
                bundle.putString(PERSONNAME,person.getName());
                bundle.putInt(TOTALBUDGET,person.getTotalBudget());
                bundle.putInt(TOTALBOUGHT,person.getTotalBought());
                bundle.putInt(GIFTCOUNT,person.getGiftCount());
                intent.putExtra("bundle",bundle);
                startActivity(intent);
            }
        });