countDownTimer Android的切换时间 [英] Android change time of countDownTimer

查看:304
本文介绍了countDownTimer Android的切换时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的申请被质疑/应答应用程序,客户机/服务器,客户端是Android应用程序,服务器是用java Tomcat服务器应用程序

我希望用户来回答在25秒内的任何问题,但我会给他时间去阅读的问题,到时候要看的字数的问题有,例如,如果该问题有10个字,我会给他10秒阅读问题,然后25秒回答,肯定谁的答案中(共25秒),10秒问题的用户将需要更多的标志是谁的答案在20秒同样问题的用户

所以我的问题是如何编辑dynamickly的countDownTimer的时间

  showHint.setText(显示提示2);
//这里我有编辑
timeToDirectAnswer.start();

我知道,有一种方法可以做到这一点的初始化与动态时间计时器,但我不想这样做,因为我的应用程序依赖于工作流和流程可以交换的,所以code会如此复杂和难以修改

也许另一种方式是使countDownTimer休眠确切秒,但以这种方式我要建一个计时器,告诉用户多少次依然开始计数标记


解决方案

 新CountDownTimer(30000,1000){     公共无效onTick(长millisUntilFinished){
         mTextField.setText(秒时:+ millisUntilFinished / 1000);
     }     公共无效onFinish(){
         mTextField.setText(完成了!);
     }
  }。开始();

这是构造函数的定义:

 公共CountDownTimer(长millisInFuture,长countDownInterval)

自:API等级1

参数

millisInFuture 开始在未来的米利斯从呼叫数(),直到倒数完成和onFinish()被调用

countDownInterval 沿途接收时间间隔onTick(长)回调

编辑:

您将不得不把这个问题在字符串变量,然后在拆分此字符串(空格)阵列,并且阵列计数将是问题的单词的数目。

然后,你会做一个公式来计算的倒计时时间阅读:

 时间为numberOfWords * 2000;

2秒,那每一个字。

my application is questioning/answering application, client/server, the client is android application, and the server is java tomcat server application

i want the user to answer any question in 25 seconds, but i will give him time to read the question, that time depends on the number of words the question has, for example if the question has 10 words i will give him 10 seconds to read the question and then 25 seconds to answer, for sure the user who answers the question in 10seconds(of the 25 seconds) will take more marks that the user who answers the same question in 20seconds

so my problems is how to edit dynamickly the time of the countDownTimer

showHint.setText("Show Hint 2");
//here i have to edit
timeToDirectAnswer.start();

i know that there is a way to do that by initializing the timer with the dynamic time, but i don't want to do that because my application depends on workflow and that flow may exchange, so the code will be so sophisticated and hard to edit

maybe another way is to make the countDownTimer sleeps for exact seconds but in this way i have to build another timer to tell user how many times remains to begin counting marks

解决方案

new CountDownTimer(30000, 1000) {

     public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
     }

     public void onFinish() {
         mTextField.setText("done!");
     }
  }.start();

This is the constructor definition:

public CountDownTimer (long millisInFuture, long countDownInterval)

Since: API Level 1

Parameters

millisInFuture : The number of millis in the future from the call to start() until the countdown is done and onFinish() is called.

countDownInterval : The interval along the way to receive onTick(long) callbacks.

EDIT:

You will have to put the question in String variable, then split this String with (space) in an Array, and the array count would be the number of words of that question.

Then, you will do an equation to calculate the countdown time for reading:

time=numberOfWords*2000;

Thats for 2 seconds each word.

这篇关于countDownTimer Android的切换时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆