-1

私はタイマーアンドロイドを使用しているAndroidアプリケーションを書いています。それは完全に機能しています。時間の経過まで毎秒振動するようにしたいと思います。

私のコードは以下のとおりです。

public class TimerActivity extends Activity {
    Button btnStart, btnStop;
    TextView textViewTime;
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_responders_timer);
            btnStop = (Button)findViewById(R.id.CanelButton);
            textViewTime  = (TextView)findViewById(R.id.textViewTime);
            textViewTime.setText("10"); 
            textViewTime.setTextSize(120);
            final CounterClass timer = new CounterClass(10000,1000);
            textViewTime.setTextSize(120);
            timer.start();

            btnStop.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    timer.cancel();
                }
            });

        }

    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
    @SuppressLint("NewApi")
    public class CounterClass extends CountDownTimer {

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

        @Override
            public void onFinish() {

            textViewTime.setTextSize(50);
            textViewTime.setText("Completed.");

            }

        @SuppressLint("NewApi")
        @TargetApi(Build.VERSION_CODES.GINGERBREAD)
        @Override
        public void onTick(long millisUntilFinished) {
            textViewTime.setText(""+millisUntilFinished / 1000);
        }
    }
4

1 に答える 1