I have a short Question about my Code.
I'm using a recyclerview in my Android App, and fill it with some data out of my Firebase Database.
It works well, but I notice that the ordering is not right :/
I have this Code:
private void getRankings() {
// hole anzahl an Teilnehmern
mDatabase.child(TEILNEHMERDATA).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// hole Anzahl aller Teilnehmer um das Ranking zu bestimmen
teilnehmerVar = (int) dataSnapshot.getChildrenCount();
mDatabase.child(TEILNEHMERDATA).orderByChild("score").addChildEventListener(new ChildEventListener() {
Teilnehmer teilnehmer = new Teilnehmer();
int i = teilnehmerVar+1;
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// teamname, Platzierung, Punkte
int punkteStand = (int) Double.parseDouble(String.valueOf(dataSnapshot.child("score").getValue()));
i -= 1;
this.teilnehmer = new Teilnehmer(dataSnapshot.getKey(), ((String) dataSnapshot.child("teamname").getValue()), "Platz " + i, punkteStand + " Punkte");
teilnehmerList.add(0, this.teilnehmer); // add to recyclerview: add(0, teilnehmer) gebe in desc aus von 0 zum n. eintrag
mAdapter.notifyDataSetChanged(); // save
}
In this row:
mDatabase.child(TEILNEHMERDATA).orderByChild("score").addChildEventListener(new ChildEventListener() {
Order Child by score
I get my Data with Structure like this:
"Teilnehmer" : {
"user_0gPpHXzKqLd2xA" : {
"image" : "",
"score" : "0",
"startnummer" : "1",
"teamname" : "Andy Foo"
},
The row score contains an Integer with a Datarange from 0 to ∞
My Layout looks like:
Teamname1 9 Punkte
Platz 1
Teamname2 0 Punkte
Platz 2
Teamname3 1000 Punkte
Platz 3
But its absolutely wrong :/
9 is bigger than 10000 seems my Query order only by the first number
1..2..3..
My Recyclerview initialization:
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
Can anyone help me out?