可能这个对你有帮助
public class MyTimePicker {
TimePickerDialog mTimePickerDialog;
public interface onTimeSet {
public void onTime(TimePicker view, int hourOfDay, int minute);
}
onTimeSet mOnTimeSet;
public void setTimeListener(onTimeSet onTimeset) {
mOnTimeSet = onTimeset;
}
public MyTimePicker(Context ctx) {
mTimePickerDialog = new TimePickerDialog(ctx, new OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mOnTimeSet.onTime(view, hourOfDay, minute);
}
}, 1, 1, true);
}
public void show() {
mTimePickerDialog.show();
}
并称之为
public void ShowTimePicker() {
MyTimePicker myTimePicker = new MyTimePicker(this);
myTimePicker.show();
myTimePicker.setTimeListener(new onTimeSet() {
@Override
public void onTime(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(MainActivity.this,
"time is " + hourOfDay + ":" + minute,
Toast.LENGTH_LONG).show();
}
});
}