9

I'm trying to look for a solution to change the title on a TimePicker dialog. Right now it says whatever the system time is (ex. "12:23 AM") but I want to change this to something a little more descriptive. Does anyone have any suggestions?

Sunandmoon
  • 297
  • 2
  • 4
  • 9
  • 3
    By TimePicker dialog do you mean the actual TimePickerDialog? Becaues that has a `setTitle(CharSequence text)` method. The TimePickerDialog is what is used in the official tutorial. http://developer.android.com/reference/android/app/AlertDialog.html#setTitle(java.lang.CharSequence) - should probably have put that as an aswer, but oh well. – Codemonkey Mar 21 '11 at 08:44
  • Oh man Klaus you're a live saver. That worked perfectly! I was worried I would have to create a custom TimePicker or something...you can give an answer and I'll mark it as solved. I have no idea how I didn't discover this, I'm really tired...Thanks so much! :) – Sunandmoon Mar 21 '11 at 08:54
  • Actually, it sets the title upon initializing the timepicker but as soon as I change a value it will reset back to the date title ("12:23 AM"). I guess I could set the title every time a value is changed but I don't know how. I think I can use a listener? – Sunandmoon Mar 21 '11 at 08:57
  • Argh, did not see your next comment. Did you add it programatically or through XML? Try both. Otherwise, hmm - not sure what the best way to do so would be. I only see 3 listeners available at first for TimePickerDialog, none of which are really helpful to you. I guess setTitle or similar is called again every time value is changed from Googles own code. – Codemonkey Mar 21 '11 at 12:13
  • Yep - look at: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/app/TimePickerDialog.java;h=a04b9e94405b62b966382f3607342883d802d703;hb=HEAD It updates the time when a new hour and minute is received. You could use the source code from there to create your own Dialog replacing the TimerPickerDialog and simply leave out the part where it automatically updates. – Codemonkey Mar 21 '11 at 12:20

3 Answers3

23

By request. :)

By TimePicker dialog do you mean the actual TimePickerDialog? Because that has a setTitle(CharSequence text) method. The TimePickerDialog is what is used in the official tutorial. http://developer.android.com/reference/android/app/AlertDialog.html#setTitle(java.lang.CharSequence)

Codemonkey
  • 3,412
  • 3
  • 20
  • 24
6

This question is rather old, but it shows up on Google results if you search this question. So, I thought I'll post my solution.

DatePicker has setCustomTitle(View view), where you can define your own view (e.g. TextView with your custom text) to be used as a title. This one does not update when changing values.

davidcesarino
  • 16,160
  • 16
  • 68
  • 109
p9teufel
  • 99
  • 1
  • 5
2

I dont know how to reply to the comments below question, so I use "Answer". By looking into source code: SourceCode

You may realize that OnTimeChangedListener is implemented by TimePickerDialog. To avoid title changed while adjusting time, you may derived from TimePickerDialog and override public void onTimeChanged(TimePicker view, int hourOfDay, int minute);

Notice, dont call super version, or it will setTitle again...

ap41047
  • 21
  • 1