Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Circular progress bar with countdown timer in Android

Ravi kumar:

I want to show a Circular Progress Bar with countdown timer.And the timer starts from 10 mins to 0.In the Textview i am showing timer and that is working fine. But it is not reflecting in the progressbar.Progress bar is not at all changing. Below is the code which i have tried.


public class MainActivity extends AppCompatActivity {
ProgressBar barTimer;
CountDownTimer countDownTimer;
TextView textTimer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
barTimer = findViewById(R.id.barTimer);
textTimer = findViewById(R.id.textTimer);
barTimer.setProgress(100);
startTimer(10);


}

private void startTimer(final int minuti) {
countDownTimer = new CountDownTimer(60 * minuti * 1000, 500) {
@Override
public void onTick(long leftTimeInMilliseconds) {
long seconds = leftTimeInMilliseconds / 1000;
barTimer.setProgress((int)seconds);
textTimer.setText(String.format("%02d", seconds/60) + ":" + String.format("%02d", seconds%60));
}
@Override
public void onFinish() {
if(textTimer.getText().equals("00:00")){
textTimer.setText("STOP");
}
else{
textTimer.setText("2:00");
barTimer.setProgress(60*minuti);
}
}
}.start();

}
}

xml code


android:id="@+id/textTimer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:id="@+id/barTimer"
android:layout_below="@+id/textTimer"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress"

/>

Can anyone please tell me where it is wrong and how to solve this?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Circular progress bar with countdown timer in Android

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×