0

I would like to make my list appear in descending order but I am not sure how to do it since I am a newbie.
This my class which fits the xml layout that includes ListView:

public class oglasna_do_UDG extends AppCompatActivity {

  BazaPodataka1 bazaPodataka1;
  ArrayList<Korisnik1> userList1;
  ListView listView1;
  Korisnik1 korisnik1;

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_oglasna_do__udg);

    bazaPodataka1 = new BazaPodataka1(this);

    userList1 = new ArrayList<>();
    Cursor data1 = bazaPodataka1.getListContents();
    int numRows = data1.getCount();
    if (numRows == 0) {
        Toast.makeText(oglasna_do_UDG.this, "Baza podataka je prazna :(.", Toast.LENGTH_LONG).show();
    } else {
        int i = 0;
        while (data1.moveToNext()) {
            korisnik1 = new Korisnik1(data1.getInt(0), data1.getString(1), data1.getString(2), data1.getString(3), data1.getString(4), data1.getString(5), data1.getString(6));
            userList1.add(i, korisnik1);
            System.out.println(data1.getString(1) + " " + data1.getString(2) + " " + data1.getString(3) + " " + data1.getString(4) + " " + data1.getString(5) + " " + data1.getString(6));
            System.out.println(userList1.get(i).getIme1());
            i++;
        }
        Adapter1 adapter1 = new Adapter1(this, R.layout.adapter1, userList1);
        listView1 = (ListView) findViewById(R.id.listView1);
        if (listView1 != null) {
            listView1.setAdapter(adapter1);
        }

    }
    Button dodaj1 = findViewById(R.id.dodaj1);
    dodaj1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(oglasna_do_UDG.this, Do_UDG.class);
            startActivity(intent);
        }
    });
  }
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • 2
    Read [Android-java- How to sort a list of objects by a certain value within the object](https://stackoverflow.com/questions/9109890/android-java-how-to-sort-a-list-of-objects-by-a-certain-value-within-the-object) then sort your `ArrayList` of `Korisnik1` objects using `Collections.sort()` – Sam Dec 11 '17 at 23:28
  • use `Collection.sort(...)` – Khalid Taha Dec 11 '17 at 23:45
  • https://stackoverflow.com/a/5894842/4336740 – Mohammad nabil Dec 12 '17 at 04:41

0 Answers0