Java Android:将日期格式和排序添加到列表视图中显示的项目的arrayList中

Java Android:将日期格式和排序添加到列表视图中显示的项目的arrayList中,java,android,date,listview,Java,Android,Date,Listview,我试图格式化一个日期列表(在用户输入时)并在列表视图中按时间顺序显示 我目前能够在列表视图中显示它们,并将它们作为未格式化的日期输入 我想将它们格式化如下:DD/MM/YYYY 这是我从db中检索日期和ID并在listView中显示的代码 第二课笔记上册: final int VALUE = extras.getInt("studentId"); mydb = new DBHelper(this); final ArrayList id_list = mydb.getAl

我试图格式化一个日期列表(在用户输入时)并在列表视图中按时间顺序显示

我目前能够在列表视图中显示它们,并将它们作为未格式化的日期输入

我想将它们格式化如下:
DD/MM/YYYY

这是我从db中检索日期和ID并在listView中显示的代码

第二课笔记上册

    final int VALUE = extras.getInt("studentId");
    mydb = new DBHelper(this);
    final ArrayList id_list = mydb.getAllLessonIds(VALUE);
    ArrayList array_list = mydb.getAllLessonNotes(VALUE);
    //Collections.sort(array_list, Collections.reverseOrder());
    //Collections.sort(array_list);
    ArrayAdapter arrayAdapter = new ArrayAdapter(this,R.layout.list_layout, array_list);
    //Adding the contacts to the list view.
    lessonNote = (ListView)findViewById(R.id.listViewLesson);
    lessonNote.setAdapter(arrayAdapter);
    //Setting an onClickListener to process the user's actions
    lessonNote.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            //Prepare the data from the ListView item to be passed to new activity
            int id_To_Search =Integer.valueOf((String)id_list.get(arg2));
            //Log.d("Id is ^&*: ", String.valueOf(id_To_Search));
            //Create a new intent to open the DisplayContact activity
            Intent lessonList = new Intent(getApplicationContext(), com.example.ltss.dyslexia.app.LessonNotes.class);
            lessonList.putExtra("studentId", VALUE);
            lessonList.putExtra("lessonId", id_To_Search);
            lessonList.putExtras(lessonList);
            startActivity(lessonList);
        }
    });

如何在用户条目上格式化日期以及如何按时间顺序排序?

sql
语句中添加ORDERBY子句

SELECT * FROM Table ORDER BY datetime(dateColumn) DESC
如果您想在用户更改日期时重新排序,请使用任何排序算法 打电话

adapter.notifyDataSetChanged();

sql
语句中添加orderby子句

SELECT * FROM Table ORDER BY datetime(dateColumn) DESC
如果您想在用户更改日期时重新排序,请使用任何排序算法 打电话

adapter.notifyDataSetChanged();

sql
语句中添加orderby子句

SELECT * FROM Table ORDER BY datetime(dateColumn) DESC
如果您想在用户更改日期时重新排序,请使用任何排序算法 打电话

adapter.notifyDataSetChanged();

sql
语句中添加orderby子句

SELECT * FROM Table ORDER BY datetime(dateColumn) DESC
如果您想在用户更改日期时重新排序,请使用任何排序算法 打电话

adapter.notifyDataSetChanged();

如果要对名为
array\u list
的日期的
ArrayList
进行排序,请尝试以下操作:

Collections.sort(array_list, new Comparator<String>() {
    DateFormat f = new SimpleDateFormat("DD/MM/YYYY");
    @Override
    public int compare(String o1, String o2) {
        try {
            return f.parse(o1).compareTo(f.parse(o2));
        } catch (ParseException e) {
            throw new IllegalArgumentException(e);
        }
    }
});

如果要对名为
array\u list
的日期的
ArrayList
进行排序,请尝试以下操作:

Collections.sort(array_list, new Comparator<String>() {
    DateFormat f = new SimpleDateFormat("DD/MM/YYYY");
    @Override
    public int compare(String o1, String o2) {
        try {
            return f.parse(o1).compareTo(f.parse(o2));
        } catch (ParseException e) {
            throw new IllegalArgumentException(e);
        }
    }
});

如果要对名为
array\u list
的日期的
ArrayList
进行排序,请尝试以下操作:

Collections.sort(array_list, new Comparator<String>() {
    DateFormat f = new SimpleDateFormat("DD/MM/YYYY");
    @Override
    public int compare(String o1, String o2) {
        try {
            return f.parse(o1).compareTo(f.parse(o2));
        } catch (ParseException e) {
            throw new IllegalArgumentException(e);
        }
    }
});

如果要对名为
array\u list
的日期的
ArrayList
进行排序,请尝试以下操作:

Collections.sort(array_list, new Comparator<String>() {
    DateFormat f = new SimpleDateFormat("DD/MM/YYYY");
    @Override
    public int compare(String o1, String o2) {
        try {
            return f.parse(o1).compareTo(f.parse(o2));
        } catch (ParseException e) {
            throw new IllegalArgumentException(e);
        }
    }
});

@BasilBourque-是的,实际上,它看起来非常像我…@BasilBourque-是的,实际上,它看起来非常像我…@BasilBourque-是的,实际上,它看起来非常像我…@BasilBourque-是的,实际上,它看起来非常像我。。。