簡體   English   中英

如果我更改值,Android倒數計時器將不起作用

[英]Android countdown timer not working if i change values

我正在嘗試制作一個程序,在第一個活動中使用數字選擇器輸入數字,在第二個活動中有一個倒數計時器,該計時器使用您在第一個活動中輸入的數字以分鍾為單位進行倒數(如果輸入10,則倒數10分鍾)。

public class timer_2 extends AppCompatActivity {
ImageButton imageButton3;
private TextView timer_2_up;
private TextView timer_2_down;
private CountDownTimer timer_2_up_countdowntimer;
private CountDownTimer timer_2_down_countdowntimer;
private boolean timer_2_up_running;
private boolean timer_2_down_running;
private long starttime;
private long starttimedown = starttime*60000;
private long starttimeup = starttime*60000;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_timer_2);
    timer_2_up = findViewById(R.id.timer_2_up);
    timer_2_down = findViewById(R.id.timer_2_down);
    imageButton3 = (ImageButton)findViewById(R.id.imageButton3);
    Bundle timer2extras = getIntent().getExtras();
    String timer2string = timer2extras.getString("timer2string");
    starttime = Integer.parseInt(timer2string);
    imageButton3.setOnClickListener(new View.OnClickListener() {
      //....                  

如果我同時在startimeup和starttimedown上刪除starttime * 60000(第9行)並替換為數字(例如600000),則可以正常工作,但使用starttime僅顯示00:00。請幫助我。

從第一個活動中獲取starttime值后,只需聲明starttimeup和starttime down即可啟動並初始化它們,例如:

long starttimeup;
long starttimedown;

並在onCreate中:

starttime = Integer.parseInt(timer2string);
starttimeup = starttime*60000;
starttimedown = starttime*60000;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM