相机应用程序计时器实现问题

时间:2016-02-12 05:18:51

标签: android android-fragments android-camera android-camera-intent

我正在研究自定义相机应用程序,但我不知道如何在自定义中实现计时器选项请帮助我谢谢.. 这是下面的代码

timer.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        final CharSequence[] items = {"2 sec", "5 sec", "10 sec"};
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("Timer");
        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int item) {
                if (items[item].equals("2 sec")) {

                } else if (items[item].equals("5 sec")) {

                } else if (items[item].equals("10 sec")) {

                }
            }
        });
        builder.show();
    }
});

1 个答案:

答案 0 :(得分:0)

您可以在if-else

中添加 CountDownTimer 匿名
  • 每秒一步,持续2秒:
new CountDownTimer(2000, 1000) {
    //just replace 2000 for 5000 to get 5 seconds
    public void onTick(long millisUntilFinished) {
            mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
           //here you can have your logic to set text to edittext
        }
        public void onFinish() {
            mTextField.setText("done!");
        }

    }.start();