[問題] Android的程式裡面加上倒數計時的功能
各位好,我是初學android的學生
我想要寫一個簡單的限時答題程式
但是我不會倒數計時的功能
我有上網找過一篇教學
http://tinyurl.com/6s2jqvx
但是編譯一直不會過,
目前我修的程式碼如下:
package demo.game;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MyCount extends CountDownTimer {
TextView timeDisplay;
MyCount counter;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.timer);
timeDisplay = (TextView) findViewById(R.id.timer);
counter = new MyCount(600000, 1000);}
private TextView findViewById(int timer) {
// TODO Auto-generated method stub
return null;
}
private MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
public void onFinish() {
timeDisplay.setText("done!");
}
public void onTick(long millisUntilFinished) {
timeDisplay.setText("Left: " + millisUntilFinished / 1000);
}
}
另外我的圖形介面的程式碼是這樣
<?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"
android:onClick="start" />
counter.start();
</LinearLayout>
但是紅字那邊會錯,請問有人可以稍微指點嗎?謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.152.187
推
12/14 22:55, , 1F
12/14 22:55, 1F
推
12/15 03:24, , 2F
12/15 03:24, 2F
→
12/15 03:25, , 3F
12/15 03:25, 3F
→
12/15 03:26, , 4F
12/15 03:26, 4F
→
12/15 03:26, , 5F
12/15 03:26, 5F
→
12/15 03:27, , 6F
12/15 03:27, 6F
→
12/15 16:23, , 7F
12/15 16:23, 7F
→
12/29 22:50, , 8F
12/29 22:50, 8F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):