zoukankan      html  css  js  c++  java
  • 寒假每日日报47(开发家庭记账本APP——进度八)

    今天将时间这一个功能给写一下,点击输入时间的文本框,会弹出一个日历

    AddActivity.java代码如下:

     1 public class AddActivity extends AppCompatActivity {
     2 
     3     //账单时间
     4     private EditText medittime;
     5 
     6     @Override
     7     protected void onCreate(Bundle savedInstanceState) {
     8         super.onCreate(savedInstanceState);
     9         setContentView(R.layout.activity_add);
    10 
    11         //时间
    12         medittime = findViewById(R.id.edittime);
    13         medittime.setOnTouchListener(new View.OnTouchListener() {
    14             @Override
    15             public boolean onTouch(View v, MotionEvent event) {
    16                 if (event.getAction() == MotionEvent.ACTION_DOWN) {
    17                     showDataPickDlg();
    18                     return true;
    19                 }
    20                 return false;
    21             }
    22         });
    23         medittime.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    24             @Override
    25             public void onFocusChange(View v, boolean hasFocus) {
    26                 if (hasFocus) {
    27                     showDataPickDlg();
    28                 }
    29             }
    30         });
    31 
    32 }
    33 //时间
    34     protected void showDataPickDlg(){
    35         Calendar calendar=Calendar.getInstance();
    36         DatePickerDialog dataPickerDialog=new DatePickerDialog(AddActivity.this, new DatePickerDialog.OnDateSetListener() {
    37             @Override
    38             public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
    39                 AddActivity.this.medittime.setText(year+"-"+(month+1)+"-"+dayOfMonth);
    40             }
    41         },calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH));
    42         dataPickerDialog.show();
    43     }
  • 相关阅读:
    layui 标签页切换
    m1配置多个git账户
    sqlserver 获取表和字段的注释方法
    springboot+mybatisPlus 配置多数据源--转载
    nginx 配置静态网页和反向代理
    ORA-01000: maximum open cursors exceeded
    重装系统我们选择FAT还是NTFS?U盘和硬盘格式化两者选谁?
    2、条件表达式
    1、javascript 知识拓展
    1_maven 问题
  • 原文地址:https://www.cnblogs.com/miao-com/p/14454225.html
Copyright © 2011-2022 走看看