如何按降序对ListView进行排序

时间:2017-12-11 23:21:20

标签: java android listview gradient-descent

我想让我的列表按降序显示,但由于我是新手,我不知道该怎么做。
这个我的类适合包含ListView的xml布局:

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);
        }
    });
  }
}

0 个答案:

没有答案