If you think the Android project ProjectStudio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/**
*//www.java2s.com
*/package dialog_fragments;
import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;
/**
* @author desmond
*/publicclass TimePickerDialogFragment extends DialogFragment implements
TimePickerDialog.OnTimeSetListener {
private TextView activity_textview;
privateint hour;
privateint minute;
public TimePickerDialogFragment() {
}
public TimePickerDialogFragment(TextView activity_textview) {
this.activity_textview = activity_textview;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
returnnew TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
@Override
publicvoid onTimeSet(TimePicker view, int hourOfDay, int minute) {
this.hour = hourOfDay;
this.minute = minute;
//PASS THE DATA BACK TO THE CALLING FRAGMENT
Intent intent = new Intent();
Bundle extras = new Bundle();
extras.putInt("hour", hourOfDay);
extras.putInt("minute", minute);
intent.putExtras(extras);
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
dismiss();
}
}