Languages

Menu
Sites
Language
How to add updated time on a button

I've written the following code:

//get system DTM
    String title, date, time;
    DateTime standardTime;
    String delim(L" ");
    SystemTime::GetCurrentTime(TIME_MODE_WALL, standardTime);
    title.Append(standardTime.ToString());
    // Creates a StringTokenizer instance
    StringTokenizer strTok(title, delim);
    strTok.GetNextToken(date);
    strTok.GetNextToken(time);
    Rectangle clientRect = GetClientAreaBounds();
// Create a Button
    Button *pButton = new (std::nothrow) Button();
    pButton->Construct(Rectangle(clientRect.width / 4, 10, 680, 160));
    pButton->SetText(time);
    pButton->SetTextColor(Color(255, 251, 251));
    pButton->SetTextSize(100);
    pButton->SetColor(BUTTON_STATUS_NORMAL, Color(42, 29, 38));

 

It is showing time..but not getting updated.

How to get updated time???

 

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

4 Replies
Oberyn Martell
I think you can use a timer, https://developer.tizen.org/help/topic/org.tizen.native.apireference/classTizen_1_1Base_1_1Runtime_1_1Timer.html and each time OnTimerExpired is called update the date and relaunch the timer
Alex Dem
Hi, I agree, you should use a timer. I think there is no another way to update your button text dinamically from current time ( 'Data Binding' don't allow do this ). 1) You should inherit your class from Tizen::Base::Runtime::ITimerEventListener and create timer. 2) You should reimplement OnTimerExpired() { ... strTok.GetNextToken(time); __pButton->SetText(time); __pButton->Invalidate(false); __timer.Start(TIMER_INTERVAL); } etc.. Alexey.
Leo Joseph
Hi Shital Bombarde, Try adding Draw(); at the end of your code.
Shital Bombarde
Hi Alex, I've implemented OnTimerExpired(), now time is getting updated :) Thanks