0% found this document useful (0 votes)
14 views2 pages

PR 13

The document provides a practical implementation of a progress bar in an Android application using XML and Java code. It includes an XML layout with a circular progress bar, a text view, and a button to initiate a file download. The Java code manages the progress of the download using a ProgressDialog and updates the progress bar in a separate thread.

Uploaded by

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

PR 13

The document provides a practical implementation of a progress bar in an Android application using XML and Java code. It includes an XML layout with a circular progress bar, a text view, and a button to initiate a file download. The Java code manages the progress of the download using a ProgressDialog and updates the progress bar in a separate thread.

Uploaded by

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

Practical no:13- Develop a program to implement a Progressbar.

 Xml code
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".pr13">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressbar2"
style="?android:attr/progressBarStyle"
android:layout_x="184dp"
android:layout_y="176dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_x="179dp"
android:layout_y="115dp"
android:text="Circular Progress Bar"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:layout_x="147dp"
android:layout_y="319dp"
android:text="Download File"/>

</AbsoluteLayout>
 Java code-
package com.example.shravani;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class pr13 extends AppCompatActivity {


int progress=0;
Handler progressHandler=new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_pr13);
Button btn=(Button)findViewById(R.id.b1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog bar=new ProgressDialog(v.getContext());
bar.setMessage("File Downloading...");
bar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
bar.setProgress(0);
bar.setMax(100);
bar.show();
new Thread(new Runnable(){
public void run() {
while (progress < 100) {
progress++;
try {
Thread.sleep(500);
} catch (Exception e) {e.printStackTrace();}
progressHandler.post(new Runnable() {
public void run() {
bar.setProgress(progress);
}
});
}
bar.dismiss();
}
}).start();
}
});
}
}

Output-

You might also like