您的位置:首页 > 移动开发 > Android开发

我的记事本项目之路(二)

2015-11-03 15:42 447 查看
        做好登陆界面之后,接下来就是记事本的主体了!首先,根据java面向对象的思想,记事本对象可以给它设置一个Note类,这样做的好处是:能够将Note()类封装起来,调用的时候只能通过get()和set()方法调用,大大的增加了安全性,Note.java代码如下:

package com.example.jishiben;

import java.io.Serializable;

public class Note implements Serializable {

    private int id;

    private String date;

    private String type;

    private String  introduction = "";

    

    public Note() {

        

    }

    

    public Note(int id, String date, String type, String introduction) {

        super();

        this.id = id;

        this.date = date;

        this.type = type;

        this.introduction = introduction;

    }

    

    public int getId() {

        return id;

    }

    public void setId(int id) {

        this.id = id;

    }

    public String getDate() {

        return date;

    }

    public void setDate(String date) {

        this.date = date;

    }

    public String getType() {

        return type;

    }

    public void setType(String type) {

        this.type = type;

    }

    public String getIntroduction() {

        return introduction;

    }

    public void setIntroduction(String introduction) {

        this.introduction = introduction;

    }

}

记事本的话,肯定还需要显示时间,这样才能根据事件的时间先后顺序进行排序,这里建一个时间工具类DateUtil.java,功能是获取系统的当前时间,并按照需要的格式进行格式化.代码如下:

package com.example.jishiben;

import java.text.SimpleDateFormat;

import java.util.Date;

public class DateUtil {

    

    public static String formatDate(long time) {

        Date date = new Date(time);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        return sdf.format(date);

    }

    

}

预知后事如何,请听下回分解.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息