Android DatePicker, TimePicker控件的使用

Android DatePicker, TimePicker控件的使用

public class TimerPickerActivity extends Activity{
 
    private DatePicker datePicker;
    private TimePicker timePicker;
    private static Calendar calendar = Calendar.getInstance();
    @Override
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.timepicker);
             
            timePicker = (TimePicker)findViewById(R.id.timePicker1);
            datePicker = (DatePicker)findViewById(R.id.datePicker1);
             
            timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
                 
                @Override
                public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                    // TODO Auto-generated method stub
                    StringBuffer buffer = new StringBuffer();
                    buffer.append(hourOfDay < 10 ? "0" + hourOfDay:hourOfDay );
                    buffer.append(":").append(minute);
                    Toast.makeText(TimerPickerActivity.this, buffer.toString(), Toast.LENGTH_SHORT).show();
                }
            });
             
            datePicker = (DatePicker)findViewById(R.id.datePicker1);
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
             
            datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() {
                 
                @Override
                public void onDateChanged(DatePicker view, int year, int monthOfYear,
                        int dayOfMonth) {
                    // TODO Auto-generated method stub
                     
                }
            });
    }
}

 



本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2013/03/08/2949283.html,如需转载请自行联系原作者

上一篇:太平保险技术总监黄雪英:客户分级认证与大数据应用


下一篇:PS批处理的使用