0% found this document useful (0 votes)
107 views3 pages

Cyclic Spinner ProgressBar Implementation

This document describes a program to create a cyclic spinner progress bar in Android. It includes a MainActivity class that uses a TimerTask to increment a ProgressBar from 0 to 100 over time, updating an associated TextView with the current progress percentage. It also includes an XML drawable resource to style the ProgressBar as a circular progress ring, and an activity_main XML layout file to display the ProgressBar and TextView on the screen.

Uploaded by

navteshdeore19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views3 pages

Cyclic Spinner ProgressBar Implementation

This document describes a program to create a cyclic spinner progress bar in Android. It includes a MainActivity class that uses a TimerTask to increment a ProgressBar from 0 to 100 over time, updating an associated TextView with the current progress percentage. It also includes an XML drawable resource to style the ProgressBar as a circular progress ring, and an activity_main XML layout file to display the ProgressBar and TextView on the screen.

Uploaded by

navteshdeore19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical 13: Program to create Determinant Cyclic Spinner ProgressBar

MainActivity.java

package com.example.practicalno13;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.PrimitiveIterator;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {


ProgressBar PB;
int counter;
TextView tw;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callme();
}

public void callme()


{
Timer t=new Timer();
TimerTask tsk= new TimerTask() {
@Override
public void run() {
PB=(ProgressBar)findViewById(R.id.progressBar2);
tw=findViewById(R.id.textView);
PB.setMax(100);
counter++;
PB.setProgress(counter);
tw.setText(PB.getProgress()+ "%");
if(counter==100)
{
t.cancel();
}
}
};
t.schedule(tsk,0,100);

}
}
Drawable Resource File ( Goto res->Drawable->create new drawable resource file)

<?xml version="1.0" encoding="utf-8"?>


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="4.5"
android:thickness="8dp"
android:useLevel="true">
<solid android:color="@color/purple_200" />
<size android:height="100dp"
android:width="100dp"></size>

</shape>

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:scrollbarStyle="outsideInset"
tools:context=".MainActivity">

<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="188dp"
android:progress="80"
android:progressDrawable="@drawable/circle_shape"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView"
android:layout_width="45dp"
android:layout_height="24dp"
app:layout_constraintBottom_toBottomOf="@+id/progressBar2"
app:layout_constraintEnd_toEndOf="@+id/progressBar2"
app:layout_constraintHorizontal_bias="0.509"
app:layout_constraintStart_toStartOf="@+id/progressBar2"
app:layout_constraintTop_toTopOf="@+id/progressBar2" />
</androidx.constraintlayout.widget.ConstraintLayout>

You might also like