我有两个TextView的一个小部件显示时间和日期。
I have a widget with two TextView showing the time and date.
我只是希望这批code的发生每秒:
I simply want this batch of code to happen every second:
views.setOnClickPendingIntent(R.id.rl, pendingIntent);
java.util.Date noteTS = Calendar.getInstance().getTime();
String time = "kk:mm";
String date = "dd MMMMM yyyy";
views.setTextViewText(R.id.tvTime, DateFormat.format(time, noteTS));
views.setTextViewText(R.id.tvDate, DateFormat.format(date, noteTS));
所以,我需要一个简单的方法,在小部件定期更新的TextView所以时间的变化比标准的30分钟以上。谢谢
So I need a simple way to update TextView periodically in the widget so the time changes more than the standard 30 mins. Thanks
您可以创建处理程序
和的Runnable
,然后让处理程序
在指定的时间重新启动的Runnable
。你的程序可能是这样的:
you may create Handler
and Runnable
, and then let the Handler
to restart your Runnable
at the specified interval. your program might look like this:
private Handler mHandler = new Handler();
@Override
public void onResume() {
super.onResume();
mHandler.removeCallbacks(mUpdateClockTask);
mHandler.postDelayed(mUpdateCLockTask, 100);
}
@Override
public void onPause() {
super.onPause();
mHandler.removeCallbacks(mUpdateClockTask);
}
private Runnable mUpdateClockTask = new Runnable() {
public void run() {
updateClock();
mHandler.postDelayed(mUpdateClockTask, 1000);
}
};
和里面的 updateClock()
你做你的所有UI更新。我想这一切都发生在活动
与适当的的onPause()/ onResume()
通话中。
and inside updateClock()
you do all your UI updates. I suppose all this happens inside the Activity
with the appropriate onPause()/onResume()
calls.
上一篇:捆绑的ArrayList< ArrayList的<整数GT;>整数、ArrayList、LT、GT
下一篇:如何GestureDetector附加到一个列表preference?列表、GestureDetector、preference