I have a firebase database that has a name and number in it for each of my stores. I want a spinner to show the names of each store so we can select one. the store name example is "0023 franklin", and i want to order them by the number.
my code to make the spinner is
mydb.orderByValue().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()) {
Store storeName = areaSnapshot.getValue(Store.class);
areas.add(storeName.getStoreName());
}
Spinner areaSpinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> areasAdapter = new ArrayAdapter<String>(checkout.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) {
}
});
it shows all the stores but doesn't order them by the number. and the stores are not added in the database in order.
how to i make this happen?
adding JSON
storelist:
-KvIoZC0AbpD1-SJJrIS
faxNum: 987654321
storeName: 0024 Franklin
-KvIobgHLouocLpMkN6k
faxNum: 1234567890
storeName: 0003 Randle