Re: [問題] Android的程式裡面加上倒數計時的功能

看板AndroidDev作者 (〆)時間14年前 (2011/12/15 11:09), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
借用一下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)

12/15 21:17, , 1F
感謝感謝
12/15 21:17, 1F
文章代碼(AID): #1EwMJ-y2 (AndroidDev)
文章代碼(AID): #1EwMJ-y2 (AndroidDev)