2. MainActivity.java
package org.me.android_timer; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.widget.TextView; public class MainActivity extends Activity { private Long startTime; private Handler handler = new Handler(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //取得目前時間 startTime = System.currentTimeMillis(); //設定定時要執行的方法 handler.removeCallbacks(updateTimer); //設定Delay的時間 handler.postDelayed(updateTimer, 1000); } //固定要執行的方法 private Runnable updateTimer = new Runnable() { public void run() { final TextView time = (TextView) findViewById(R.id.timer); Long spentTime = System.currentTimeMillis() - startTime; //計算目前已過分鐘數 Long minius = (spentTime/1000)/60; //計算目前已過秒數 Long seconds = (spentTime/1000) % 60; time.setText(minius+":"+seconds); handler.postDelayed(this, 1000); } }; }
3. main.xml(Layout)
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <TextView android:id="@+id/timer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0:0" android:textSize="70sp" android:layout_x="90px" android:layout_y="160px" > </TextView> </AbsoluteLayout>
4. 執行之後的畫面。
Hi.
回覆刪除I want to know if you have the Timer Call app to drop calls on android at X minutes. Can u send me the apk, cause i want find to install.
thank u
martyn.write at gmail dot com
Thank you~Thank you~這篇文章有幫助到我
回覆刪除我看到曙光!!感謝!!
回覆刪除謝啦~
回覆刪除