Android DatePicker, TimePicker控件的使用
Posted on 2013-03-08 09:41 work hard work smart 阅读(600) 评论(0) 编辑 收藏 举报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/
欢迎任何形式的转载,未经作者同意,请保留此段声明!