How to arrange list item in spinner in descending order


How to arrange items in list descending instead of the image:

to be like this:

10
20
50
100

and this is the below adapter I use:

package com.appgain.BeetElKhairCharity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


import com.appgain.BeetElKhairCharity.R;

import java.util.ArrayList;
import java.util.List;

public abstract class GenericArrayAdapter<T> extends ArrayAdapter<T> {

  // Vars
  private LayoutInflater mInflater;

  public GenericArrayAdapter(Context context, List<T> objects) {
    super(context, 0, objects);
    init(context);
  }

  // Headers
  public abstract void drawText(TextView textView, T object);
  public abstract void drawSubText(TextView textView, T object);

  private void init(Context context) {
    this.mInflater = LayoutInflater.from(context);
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.simple_spinner_item, parent, false);
      vh = new ViewHolder(convertView);
      convertView.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    drawText(vh.textView, getItem(position));

    return convertView;
  }

  static class ViewHolder {

    TextView textView;

    private ViewHolder(View rootView) {
      textView = (TextView) rootView.findViewById(R.id.row_text);
    }
  }

  static class ViewHolderSub {

    TextView textView;

    private ViewHolderSub(View rootView) {
      textView = (TextView) rootView.findViewById(R.id.sub_text);
    }
  }
  @Override
  public View getDropDownView(int position, View convertView, ViewGroup parent) {
    final ViewHolderSub vh;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.simple_spinner_item_child, parent, false);
      vh = new ViewHolderSub(convertView);
      convertView.setTag(vh);
    } else {
      vh = (ViewHolderSub) convertView.getTag();
    }

    drawSubText(vh.textView, getItem(position));

    return convertView;
  }
}

and this is the full code how I pass the adapter:

                final GenericArrayAdapter operatorAdapter = new GenericArrayAdapter<Map.Entry>(getContext(), filterSms()) {
                    @Override
                    public void drawText(TextView textView, Map.Entry object) {


                        textView.setText(object.getKey().toString());


                    }

                    @Override
                    public void drawSubText(TextView textView, Map.Entry object) {
                        textView.setText(object.getKey().toString());

                    }


                };

                operatorAdapter.setDropDownViewResource(R.layout.simple_spinner_item);
                operspiner.setAdapter(operatorAdapter);


                List<Sm> tempList = new ArrayList<>();
                Sm sm = new Sm();
                tempList.add(sm);
                final GenericArrayAdapter priceAdapter = new GenericArrayAdapter<Sm>(getContext(), slectedSmsEntities) {
                    @Override
                    public void drawText(TextView textView, Sm object) {
                        if (object != null && object.getPrice() != null) {
                            if (LngID == 0)
                                textView.setText(object.getPrice() + "");
                            else {
                                textView.setText(object.getPrice() + "");

                            }
                        }

                    }

                    @Override
                    public void drawSubText(TextView textView, Sm object) {
                        if (object != null && object.getPrice() != null) {
                            if (LngID == 0)
                                textView.setText(object.getPrice() + "");
                            else {
                                textView.setText(object.getPrice() + "");

                            }
                        }
                    }


                };

                priceAdapter.setDropDownViewResource(R.layout.simple_spinner_item);
                amountspiner.setAdapter(priceAdapter);


                operspiner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                        slectedSmsEntity = null;
                        slectedSmsEntities = (List<Sm>) ((Map.Entry) operatorAdapter.getItem(i)).getValue();
                        Log.e("slectedSmsEntities", slectedSmsEntities.size() + " size");

                        setupPrice();
                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> adapterView) {

                    }
                });


                amountspiner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                        slectedSmsEntity = (Sm) priceAdapter.getItem(position);

                        Log.e("slectedSmsEntities", slectedSmsEntity.toString());


                    }

                    public void onNothingSelected(AdapterView<?> parent) {
                    }
                });

and this is the setupPrice() method:

    private void setupPrice() {
        final GenericArrayAdapter priceAdapter = new GenericArrayAdapter<Sm>(getContext(), slectedSmsEntities) {
            @Override
            public void drawText(TextView textView, Sm object) {
                if (object != null && object.getPrice() != null) {
                    if (LngID == 0)
                        textView.setText(object.getPrice() + "");
                    else {
                        textView.setText(object.getPrice() + "");

                    }
                }

            }

            @Override
            public void drawSubText(TextView textView, Sm object) {
                if (object != null && object.getPrice() != null) {
                    if (LngID == 0)
                        textView.setText(object.getPrice() + "");
                    else {
                        textView.setText(object.getPrice() + "");

                    }
                }
            }


        };

        priceAdapter.setDropDownViewResource(R.layout.simple_spinner_item);
        amountspiner.setAdapter(priceAdapter);

        amountspiner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                slectedSmsEntity = (Sm) priceAdapter.getItem(position);

                Log.e("slectedSmsEntities", slectedSmsEntity.toString());


            }

            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

    }
---------------Answer---------------

You can implement a Comparator like this for your Sm class before passing it into the adapter. Just like what the first comment said.

Collections.sort(tempList, new Comparator<Sm>(){
    public int compare(Sm s1, Sm s2) {
            return s1.getPrice() > s2.getPrice();
        }
});

Previous : Data doesn't load until refreshed or reloaded in Flutter
Next : Why am I getting this runtime error? Line 1034: Char 9: runtime error: reference binding to null pointer of type 'int'