2016-08-01 68 views
-3

我希望活動時間每分鐘更新一次,而不僅僅是創建。這是我的代碼至今:更新時間顯示每分鐘,而不僅僅是創建?

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

嘗試使用鬧鐘 – dadan

回答

0

嘗試使用可運行和這樣的處理程序:

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(); 
0

這是我的代碼至今

new Timer().schedule(new TimerTask() { 

     @Override 
     public void run() { 
      runOnUiThread(new Runnable() { 
       public void run() { 
       } 
      }); 
     } 
},0,1000); 

什麼我想要做的是替換,0,1000);最後有60分鐘 - 目前的時間。

相關問題