mkounal
mkounal

Reputation: 783

Time picker with dialog

Hello I need to set a dialog of a time picker and return the results that the user states.

Right now I have that code

.
.
.
showDialog(0);
.
.
.

@Override
    protected Dialog onCreateDialog(int id) {

              return  new TimePickerDialog(this, mTimeSetListener, hour, minute,
                        false);

    }

That code sets a dialog of a time picker, but I have not found a way yet to return the results.

Upvotes: 0

Views: 354

Answers (2)

mkounal
mkounal

Reputation: 783

           int StartHour;
           int StartMinute;
           TimePickerDialog.OnTimeSetListener mTimeSetListenerStart = new TimePickerDialog.OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minutex) {
                // TODO Auto-generated method stub
            StartHour = hourOfDay;
            StartMinute = minutex;
            Log.d("TimeStart", StartHour+" "+StartMinute);
            } };

Upvotes: 1

Gorets
Gorets

Reputation: 2442

protected Dialog onCreateDialog(int id) {
  if (id == DIALOG_TIME) {
    TimePickerDialog tpd = new TimePickerDialog(this, myCallBack, myHour, myMinute, true);
    return tpd;
  }
  return super.onCreateDialog(id);
}

OnTimeSetListener myCallBack = new OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
  myHour = hourOfDay;
  myMinute = minute; 
  tvTime.setText("Time is " + myHour + " hours " + myMinute + " minutes");
}

};

Upvotes: 0

Related Questions