我希望活动时间每分钟更新一次,而不仅仅是创建。这是我到目前为止的代码:
public class MainActivity extends ActionBarActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TimeZone tz = TimeZone.getTimeZone("Atlantic/St_Helena");
Calendar c = Calendar.getInstance(tz);
String timez = String.format("Year "+"%02d" , c.get(Calendar.YEAR))
// Display formattedDate value in TextView
TextView time = new TextView(this);
time.setText("Its"+timez+" PM"+"\n\n"+"Ants stretch when they wake up in the morning.");
time.setGravity(Gravity.TOP);
time.setTextSize(20);
setContentView(time);
}}
答案 0 :(得分:0)
尝试使用runnable和这样的处理程序:
handler=new Handler();
new Runnable() {
public void run() {
c = Calendar.getInstance(tz);
timez = String.format("Year "+"%02d", c.get(Calendar.YEAR));
time.setText("Its"+timez+" PM"+"\n\n"+"Ants stretch when they wake up in the morning.");
time.setGravity(Gravity.TOP);
time.setTextSize(20);
setContentView(time);
handler.postDelayed(this, 60000);
}
}.run();
答案 1 :(得分:0)
这是我到目前为止的代码
new Timer().schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
}
});
}
},0,1000);
我想做的是替换,0,1000);最后有60分钟 - 当前时间。