just convert the remaining time in the second (get the hour value from db and convert it to the second, in my case I get the time in seconds)
public class CountDownActivity extends Activity { int time,initStart,startPointTime,hh,mm,ss,millis; TextView txtSecond; TextView txtMinute; TextView txtHour; TextView txtDay; Handler handler; long seconds =40*60*60; Runnable updater; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); txtSecond=(TextView)findViewById(R.id.cntSecond); txtMinute=(TextView)findViewById(R.id.cntMinute); txtHour=(TextView)findViewById(R.id.cntHour); txtDay=(TextView)findViewById(R.id.cntDay); handler= new Handler(); initStart = (int) SystemClock.elapsedRealtime(); updater = new Runnable() { public void run() { int sec,minute,hour,day; long diff = seconds; System.out.println(diff); if (diff >= 1) { sec = (int) (diff%60); } else { sec=00; } txtSecond.setText("" +sec); diff = diff/60; System.out.println(diff); if (diff >= 1) { minute = (int) (diff%60); } else { minute=00; } txtMinute.setText("" +minute); diff = diff/60; if (diff >= 1) { hour = (int) (diff%24); } else {hour = 00; } txtHour.setText("" +hour); diff = diff/24; if (diff >= 1) { day = (int) diff; } else { day =00; } txtDay.setText("" +day); seconds=seconds-1; handler.postDelayed(this, 1000); } }; handler.post(updater); } > //and don't forget to removeCallback on destroy @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); handler.removeCallbacks(updater); } }
source share