0

In this format i have databse in firebase.I have to display all the departments in the form of array list like Director,sports.

firebase

mAuth=FirebaseAuth.getInstance();
 mdatabase=FirebaseDatabase.getInstance().getReference().child("Department";
mdatabase.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        List<String> Department = (ArrayList<String>) dataSnapshot.getValue();
         DepartmentLIST=Department.toArray(new String[Department.size()]);

    }
   @Override
   public void onCancelled(DatabaseError databaseError) {
       Toast.makeText(CheckUpdate.this,databaseError.getMessage(),Toast.LENGTH_LONG).show();
   }

  });

setListAdapter(new ArrayAdapter(this,
        android.R.layout.simple_list_item_1,DepartmentLIST));

}

This is my code i have used for it. But it gives NullValue.

1 Answer 1

1

(ArrayList<String>) dataSnapshot.getValue() isn't correct.

I think you are looking for dataSnapshot.getChildren(), and / or dataSnapshot.getValue(String.class).

Note: Firebase-UI library could help you here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.