码迷,mamicode.com
首页 > 其他好文 > 详细

timepicker,datepicker

时间:2015-10-09 11:47:09      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

首先的思路就是想把datepincker和timepincker的内容显示到edt里,要先要有个方法来设置里面的东西
然后time就用setOnTimeChangedListener
而date没有这个方法要用init方法(设置年份,月份,天数,OnDateChangedListener());
最后在他们的点击事件里调用setdate方法就可以\

package com.example.datapinkertimepinker;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.EditText;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;

public class MainActivity extends Activity {

    private EditText show;
    private TimePicker time;
    private DatePicker date;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        show = (EditText) findViewById(R.id.show);
        time = (TimePicker) findViewById(R.id.time);
        date = (DatePicker) findViewById(R.id.date);

        this.getDate();
        time.setOnTimeChangedListener(new OnTimeChangedListener() {

            @Override
            public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                // TODO Auto-generated method stub
                MainActivity.this.getDate();
            }
        });
        date.init(date.getYear(), date.getMonth(), date.getDayOfMonth(), new OnDateChangedListener() {
            
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear,
                    int dayOfMonth) {
                // TODO Auto-generated method stub
                
                MainActivity.this.getDate();
            }
        });
    }

    private void getDate() {
        show.setText(date.getYear() + "-" + (date.getMonth() + 1) + "-"
                + date.getDayOfMonth() + " " + time.getCurrentHour() + ":"
                + time.getCurrentMinute());
    }

}

 

timepicker,datepicker

标签:

原文地址:http://www.cnblogs.com/84126858jmz/p/4863287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!