该方法实现的调用系统Api,和android的版本,手机的牌子有关,实现不同的界面。不一定是入下图所示:

                                    

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

<?xml version="1.0" encoding="utf-8"?>

"http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:orientation="vertical" >

    

        android:id="@+id/text01"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="查询日期:"

        android:textSize="18sp"

        />

    

        android:id="@+id/tvDate"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_below="@id/text01"

        android:layout_alignLeft="@id/text01"

        />

    

        android:id="@+id/btnDatePicker"

        android:text="编辑"

        android:layout_toRightOf="@id/tvDate"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:onClick="show"

        android:layout_alignTop="@id/tvDate"

        />

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

package com.turboradio;

 

import java.text.SimpleDateFormat;

import java.util.Calendar;

 

import android.app.Activity;

import android.app.DatePickerDialog;

import android.os.Bundle;

import android.view.View;

import android.widget.DatePicker;

import android.widget.TextView;

 

public class DatePickerActivity extends Activity {

    private TextView tvDate;

    private Calendar cal = Calendar.getInstance();

    private DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {

         

        @Override

        public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {

            cal.set(Calendar.YEAR, year);

            cal.set(Calendar.MONTH, monthOfYear);

            cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);

            updateDate();

        }

    };

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.date_picker_dialog);

        tvDate = (TextView)findViewById(R.id.tvDate);

         

    }

    public void show(View v){

        new DatePickerDialog(DatePickerActivity.this,listener,

                cal.get(Calendar.YEAR),

                cal.get(Calendar.MONTH),

                cal.get(Calendar.DAY_OF_MONTH)

                ).show();

    }

    private void updateDate(){

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        tvDate.setText(simpleDateFormat.format(cal.getTime()));

    }

}

 

 

 

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. python list.sort()根据多个关键字排序的方法实现
  3. Android应用程序组件Content Provider的启动过程源代码分析(5)
  4. Android代码实现APK文件的安装与卸载
  5. Android短信----接收流程---框架层(Frameworks)
  6. android下usb框架系列文章---(3)Storage框架整理
  7. android 9.0 startService启动Servcie的过程分析
  8. Android增加监听的三种实现方式
  9. Android之SurfaceView实现视频播放

随机推荐

  1. android gps ,wifi ,基站定位集合
  2. 关于java.lang.NoSuchMethodException: [
  3. Android实现简单画图画板
  4. Android 调用intent 拍照
  5. Mac 真机调试android程序
  6. Android(安卓)Launcher全面剖析
  7. android 安装内核module,提示Required key
  8. flutter 打包 flutter build apk 报错Pro
  9. android 里的actionbar最右边的overflow
  10. Epub加密