体温2

今天完成了体温登记app的日期的自动生成

此为日期选择器在MainActivity内的代码

复制代码
 1 private EditText mData;
 2 @Override
 3 protected void onCreate(Bundle savedInstanceState) {
 4      super.onCreate(savedInstanceState);
 5      setContentView(R.layout.activity_main);
 6       //日期选择器
 7       mData = findViewById(R.id.data);
 8       mData.setOnTouchListener(new View.OnTouchListener() {
 9       @Override
10       public boolean onTouch(View v, MotionEvent event) {
11           if (event.getAction() == MotionEvent.ACTION_DOWN) {
12                showDataPickDlg();
13                return true;
14           }
15                return false;
16           }
17        });
18        mData.setOnFocusChangeListener(new View.OnFocusChangeListener() {
19             @Override
20             public void onFocusChange(View v, boolean hasFocus) {
21                 if (hasFocus) {
22                     showDataPickDlg();
23                 }
24            }
25        });
26 }
27 protected void showDataPickDlg(){
28      Calendar calendar=Calendar.getInstance();
29      DatePickerDialog dataPickerDialog=new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() {
30             @Override
31             public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
32                 MainActivity.this.mData.setText(year+"-"+(month+1)+"-"+dayOfMonth);
33             }
34         },calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH));
35         dataPickerDialog.show();
36     }
复制代码

参考博客:https://blog.csdn.net/hzh_csdn/article/details/52317876?utm_source=app&app_version=4.5.1

明天计划完成时间的自动生成。

posted @ 2021-02-09 22:34  一口獠牙  阅读(75)  评论(0编辑  收藏  举报