bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cd = Calendar.getInstance();
cd.setTimeInMillis(System.currentTimeMillis());
int hour = cd.get(Calendar.HOUR_OF_DAY);
int minute = cd.get(Calendar.MINUTE);
new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
cd.setTimeInMillis(System.currentTimeMillis());
cd.set(Calendar.HOUR_OF_DAY, hourOfDay);
cd.set(Calendar.MINUTE, minute);
cd.set(Calendar.SECOND, 0);
cd.set(Calendar.MILLISECOND, 0);
Toast.makeText(MainActivity.this, cd.get(Calendar.HOUR_OF_DAY) + ":" + cd.get(Calendar.MINUTE), Toast.LENGTH_SHORT).show();
}
}, hour, minute, true).show();
}
});
转载于:https://www.cnblogs.com/manong-xxf/p/10724960.html