返回顶部

一缕半夏微光

温柔半两,从容一生

导航

体温登记app——进度3

今天将时间的自动生成完成了

以下是在MainActivity里面的关于自动生成时间这一块的代码

private EditText mTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //时间
    mTime=findViewById(R.id.time);
    mTime.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
                showTime();
                return true;
        }
                return false;
        }
   });
}
protected  void showTime(){
     SimpleDateFormat simpleDateFormat=new SimpleDateFormat("HH:mm:ss");
     Date date=new Date(System.currentTimeMillis());
     mTime.setText(simpleDateFormat.format(date));
}

明天计划完成地点的自动生成。

posted on 2021-02-03 22:22  一缕半夏微光  阅读(98)  评论(0编辑  收藏  举报