0

我有一个应用程序,我可以在其中创建一些课程(英语、法语、...)。这些课程有一个开始和结束日期。我将选定的日期作为字符串存储在我的数据库中。

我想知道创建一个带有 3 个选项卡(过去/当前/未来)的 TabbedActivity。

Past 将包含日期结束在当前日期之前的所有课程。Current 将包含当前日期在 2 个日期的开始和结束之间的所有课程。Futur 将包含开始日期在当前日期之后的所有课程。

但是,由于我将它们存储为字符串值,这可能吗?如果是,你能解释一下怎么做吗?

如果您需要,我可以发布一些代码(我现在不发布代码,因为如果可能的话,我要问的是什么)。

感谢你们!

@update 使用助手中的方法

 public Cursor getCoursFuture()
{
    Calendar c = Calendar.getInstance();
    DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    Date date = c.getTime();
    String currentDate = df.format(date);

    String query ="select ID as _id, branche_cours, designation from "+TABLE_COURS+" where date('"+COLONNE_DATEPREMIER+"') > '"+currentDate+"'";
    Open();
    Cursor cursor = db.rawQuery(query,null);
    return cursor;
}

我的 SimpleCursorAdapter

    lvCours =(ListView)findViewById(R.id.ListCours);
    final Cursor cursor = dbhelper.getCoursFuture();
    String[] from = { "branche_cours", "designation" };
    int[] to = { R.id.text_branche_cours, R.id.text_designation };
    lvCours.setAdapter(adapter);
    adapter = new SimpleCursorAdapter(this, R.layout.list_row, cursor, from, to, 0);
    lvCours.setAdapter(adapter);
    adapter.notifyDataSetChanged();
4

1 回答 1

0

可以按日期排序

假设您的当前日期是currentDate

您可以使用此查询进行排序以选择未来的课程

select * from Table where date(dateColumn) > currentDate

替换><=其他查询。

编辑:当您调用 c.getTime() 时,您会得到一个日期对象。您需要将其格式化为字符串。

Date date = c.getTime(); 
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String currentDate = df.format(date);
于 2017-05-07T11:51:38.090 回答