I am using FirebaseRecyclerAdapter.
I have many nodes with a child "maxValue". Let's say I have five nodes, the max values of each when listed are 34, 210, 90, 315, 74.
I expected .oderByChild("maxValue") to order them like this: 315, 210, 90, 74, 34.
However, it returns them as 90, 74, 210, 34, 314.
So it is checking the first digit, then if two entries have the same first digit, it then sorts by the second digit.
I need to it to sort by the value of the whole number. Is this possible or will I have to take the data and sort it myself?
Edit: Here is my full code setting up the FirebaseRecyclerAdapter.
Query query = databaseReference.orderByChild("maxValue");
FirebaseRecyclerOptions<ExerciseMaxesModelClass> options = new FirebaseRecyclerOptions
.Builder<ExerciseMaxesModelClass>()
.setQuery(query, ExerciseMaxesModelClass.class)
.build();
firebaseAdapter = new FirebaseRecyclerAdapter<ExerciseMaxesModelClass, ExerciseMaxesViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ExerciseMaxesViewHolder holder, int position,
@NonNull ExerciseMaxesModelClass model) {
holder.setDate(model.getDate());
holder.setExerciseName(model.getExerciseName());
holder.setIsImperial(model.isIsImperial());
holder.setIsImperialPOV(isImperial);
holder.setMaxValue(model.getMaxValue());
}
@Override
public ExerciseMaxesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.exercise_maxes_list_item, parent, false);
return new ExerciseMaxesViewHolder(view);
}
};
What an example node looks like:
Bench Press (Barbell - Flat)
- date: "2019-11-28"
- exerciseName: "Bench Press (Barbell - Flat)"
- isImperial: true
- maxValue: "315"
Edit 2: I'm happy with the workaround I've posted as an answer, but apparently I can't accept my own answer yet. Now that I'm looking at the node, the answer might simply be because I am storing the max value as a string, so it of course doesn't sort it as an int.