package com.moon.hello2;import java.util.Calendar;import android.R.anim;import android.R.integer;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;import android.widget.DatePicker;import android.widget.DatePicker.OnDateChangedListener;import android.widget.TextView;import android.widget.TimePicker;import android.widget.TimePicker.OnTimeChangedListener;public class MainActivity extends Activity { private int year; private int month; private int day; private int hour; private int minute; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_main); DatePicker datePicker = (DatePicker)findViewById(R.id.date); TimePicker timePicker = (TimePicker)findViewById(R.id.time); Calendar calendar = Calendar.getInstance(); datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),new OnDateChangedListener(){ @Override public void onDateChanged(DatePicker date, int year, int month, int day) { // TODO Auto-generated method stub MainActivity.this.year = year; MainActivity.this.month = month; MainActivity.this.day = day; showDate(); } }); timePicker.setOnTimeChangedListener(new OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker arg0, int hour, int minute) { // TODO Auto-generated method stub MainActivity.this.hour = hour; MainActivity.this.minute = minute; showDate(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } private void showDate(){ TextView textView = (TextView)findViewById(R.id.textView1); textView.setText(year+"年"+month+"月"+day+"日"+hour+"小时"+minute+"分"); }}