example of how popular a spinner with firebase data

1

I'm having trouble popping a spinner with firebase data ...

is as follows:

I have an "activity room" with the rooms registered and listed in a listview, saved in firebase ... I created a new "activity schedule" with a spinner component that is populated by these rooms that are in the "activity room", but I have no idea how to do this, that is, pass data from one activity to another and pick up this data is popular in the spinner. Could you help me?

    
asked by anonymous 25.08.2017 / 00:03

1 answer

0

Try this:

fDatabaseRoot.child("areas").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        // Is better to use a List, because you don't know the size 
        // of the iterator returned by dataSnapshot.getChildren() to
        // initialize the array
        final List<String> areas = new ArrayList<String>();

        for (DataSnapshot areaSnapshot: dataSnapshot.getChildren()) {
            String areaName = areaSnapshot.child("areaName").getValue(String.class);
            areas.add(areaName);
        }

        Spinner areaSpinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<String> areasAdapter = new ArrayAdapter<String>(UAdminActivity.this, android.R.layout.simple_spinner_item, areas);
        areasAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        areaSpinner.setAdapter(areasAdapter);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {

    }
});

Response link: link

    
25.08.2017 / 20:16