1

私は新しいアンドロイド開発者です。最近、ワードパズルアプリ「Wozzle」をリリース

ゲームにタイマーを追加して、プレーヤーが限られた時間を移動できるようにしたいと考えています。どうやってするか ?また、タイマーをプレイヤーに表示する必要があります。

4

1 に答える 1

4

これを試して、

public class CountDownTest extends Activity {

    TextView tv; // textview to display the countdown

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tv = new TextView(this);
        this.setContentView(tv);

        // 5000 is the starting number (in milliseconds)
        // 1000 is the number to count down each time (in milliseconds)
        MyCount counter = new MyCount(5000, 1000);

        counter.start();

    }

    //countdowntimer is an abstract class, so extend it and fill in methods
    public class MyCount extends CountDownTimer{

        public MyCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onFinish() {
            tv.setText("done!");
        }

        @Override
        public void onTick(long millisUntilFinished) {
            tv.setText("Left: " + millisUntilFinished/1000);

        }

    }
}

これらのリンクを見てください

于 2012-08-23T04:31:15.297 に答える