的记事本之--主界面和功能实现

      今天我们添加主页界面个功能,以后只会贴出主要的方法,想要全部源码的同学请下载源码!
     在主页,我们提供两个按钮:最新记事,所有记事。
     我们来说一下最新记事:展示七天之内的所有记事简略信息。为此我们需要获取当前七天之内的记事,代码如下:
    //获取最近七天的记事
public static List<Note> getSevenNote() {
List<Note> list = new ArrayList<Note>();
Cursor cur = db.query(TABLE_NAME_NOTE, null, "created_at > ?", new String[]{getNTime(7)}, null, null, " created_at desc", null);
if (cur != null) {
if (cur.moveToFirst()) {
do {
Note note = new Note();
note.setId(cur.getInt(cur.getColumnIndex("id")));
note.setTitle(cur.getString(cur.getColumnIndex("title")));
note.setContent(cur.getString(cur.getColumnIndex("content")));
note.setCreated_at(cur.getString(cur.getColumnIndex("created_at")));
list.add(note);
} while(cur.moveToNext());
}
cur.close(); //不要忘记关闭链接
}
return list;
}
      相应主界面主要就是把查出的信息利用ListView显示,主要代码如下:
       latest.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
List<Note> list = DBUtil.getSevenNote(); //获取最近七天的记事
initDate(list); //初始化数据集合
SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, daList, R.layout.activity_nolist_item, new String[]{"time", "notitle"}, new int[]{R.id.time, R.id.notitle}); //使用SimpleAdapter
nolist.setAdapter(adapter);
}
});

源码下载 http://www.exceptionhelp.com/posts/545

猜你喜欢

转载自exceptionhelp.iteye.com/blog/2050196