2016-08-30 5 views
-1

Ich habe ein Problem mit ProgressBar, weil es nicht richtig angezeigt wird.Progressbar wird nicht korrekt angezeigt

Video

Code:

private void setTimer() { 

    if(np3.getValue() == 0){ 
     time_one = (np1.getValue()) + (np2.getValue() * 60); 
     totalTimeCountInMilliseconds = time_one * 1000; 
    } else { 
     time_two = (np1.getValue()) + (np2.getValue() * 60) + ((np3.getValue() * 3600)-3600); 
     totalTimeCountInMilliseconds = time_two * 1000; 
    } 
    np1.setVisibility(View.GONE); 
    np2.setVisibility(View.GONE); 
    np3.setVisibility(View.GONE); 
    textViewShowTime.setVisibility(View.VISIBLE); 

    timeseconds = 10 * 1000; 
} 

private void startTimer() { 
    countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds, 500) { 
     @Override 
     public void onTick(long leftTimeInMilliseconds) { 

       if (leftTimeInMilliseconds <= timeseconds) { 
        if(change == false){ 
         textViewShowTime.setVisibility(View.VISIBLE); 
         textViewShowTime.setTextSize(20); 
         textViewShowTime.setTextAppearance(getApplicationContext(), 
           R.style.RedText); 
         change = true; 
        } else{ 
         textViewShowTime.setVisibility(View.GONE); 
         change = false; 
        } 
       } 

      if(np3.getValue() == 0){ 
       Date date = new Date(leftTimeInMilliseconds); 
       DateFormat formatter = new SimpleDateFormat("mm:ss"); 
       String dateFormatted = formatter.format(date); 
       textViewShowTime.setText(String.format(dateFormatted)); 
       textViewShowTime.setTextSize(40); 
       pb.setVisibility(View.VISIBLE); 

       if(progressStatus <100){ 
        int end_time = 100/time_one; 
        progressStatus += end_time; 
        pb.setProgress(progressStatus); 
       } 

Antwort

0

Hier ist das Problem.

new CountDownTimer(totalTimeCountInMilliseconds, 500) 

Wenn Sie 1 Sekunde simulieren wollen, warum Sie tick es auf 500 sind. Es sollte sein.

Aufgrund dieses Problems füllte sich Ihre ProgressBar schnell. Ändern Sie es in

new CountDownTimer(totalTimeCountInMilliseconds, 1000) 

Aktualisieren Sie dies. Ich glaube nicht, Sie benötigen change boolean

textViewShowTime.setVisibility(View.VISIBLE); 
textViewShowTime.setTextSize(20); 
textViewShowTime.setTextAppearance(getApplicationContext(),R.style.RedText); 
+0

änderte ich schon, aber dann hatte ich ein Problem mit dem blinkenden Text zu sagen, dass es nicht das, was ich wollte:/ – tomecki

+0

ich geändert und jetzt gibt es so etwas https://drive.google.com/file/d/0B3LWRfNDCNdBSHB6RGRxTUYydXc/view?usp=sharing – tomecki

+0

können Sie Ihre Frage aktualisieren. –

Verwandte Themen