推 kkeeennnn:感謝感謝 12/15 21:17
借用一下XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:text="TextView"
android:id="@+id/timer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
/>
</LinearLayout>
MyCount.java
import 省略...(按Ctrl+Shift+o就會自己產生)
public class MyCount extends Activity{
TextView timeDisplay;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.timer);
timeDisplay = (TextView)findViewById(R.id.timer);
mCountDownTimer.start();
}
private CountDownTimer mCountDownTimer = new CountdownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
timeDisplay.setText("seconds remaining: "
+ millisUntilFinished/1000);
}
public void onFinish() {
timeDisplay.setText("done!");
}
};
}
官網上複製貼上的
http://developer.android.com/reference/android/os/CountDownTimer.html
不過官網有小錯CountDownTimer 寫成 CountdownTimer
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.221.115.4
※ 編輯: givemepass 來自: 61.221.115.4 (12/15 11:15)