Android Working with TimePickerDialog

CustomTimePickerDialog.java

public class CustomTimePickerDialog extends DialogFragment {
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        Calendar calendar= Calendar.getInstance();
        int hour=calendar.get(Calendar.HOUR_OF_DAY);
        int minute=calendar.get(Calendar.MINUTE);

        TimePickerDialog timePickerDialog=new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                String time=String.format("%s:%s",hourOfDay,minute);
                Toast.makeText(getContext(),time,Toast.LENGTH_LONG).show();
            }
        },hour,minute,false);

        return timePickerDialog;
    }
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

    Button buttonShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        buttonShow= (Button) findViewById(R.id.buttonShow);

        buttonShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CustomTimePickerDialog customTimePickerDialog=new CustomTimePickerDialog();
                customTimePickerDialog.show(getSupportFragmentManager(),"customDialog1");
            }
        });
    }
}

References
https://github.com/mhdr/AndroidSamples/tree/master/018