0% found this document useful (0 votes)
17 views8 pages

Mad 13

The document provides two programs for implementing progress bars in Android applications. The first program displays a circular progress bar that toggles visibility with a button click, while the second program shows a vertical progress bar using a progress dialog that simulates a download process. Both programs include XML layout files and corresponding Java code for functionality.

Uploaded by

saeedarwatkar
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)
17 views8 pages

Mad 13

The document provides two programs for implementing progress bars in Android applications. The first program displays a circular progress bar that toggles visibility with a button click, while the second program shows a vertical progress bar using a progress dialog that simulates a download process. Both programs include XML layout files and corresponding Java code for functionality.

Uploaded by

saeedarwatkar
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/ 8

Practical No.

13 : Write a program to implement


Progress Bar
1.Write a program to display Circular Progress Bar

 XML File:

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/main"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

tools:context=".MainActivity">

<ProgressBar

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/progressBar"

style="@android:style/Widget.ProgressBar.Large"

android:visibility="gone"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Start Progress"

android:layout_marginTop="20dp"

android:id="@+id/btn"/>

</LinearLayout>

 Java File:

package com.example.myapplication;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.ProgressBar;

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 MainActivity extends AppCompatActivity {

ProgressBar pg;

Button b;

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

EdgeToEdge.enable(this);

setContentView(R.layout.activity_main);

pg=findViewById(R.id.progressBar);

b=findViewById(R.id.btn);

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

if(pg.getVisibility()==View.GONE)

pg.setVisibility(View.VISIBLE);

b.setText("Stop Progress");

else {

pg.setVisibility(View.GONE);

b.setText("Start Progress");

});

}
Output:
2. Write a program to display vertical progress bar

 XML file:

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/main"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

tools:context=".MainActivity">

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Download File"

android:layout_marginTop="20dp"

android:id="@+id/btn"/>

</LinearLayout>

 Java File:

package com.example.myapplication;
import android.app.ProgressDialog;

import android.os.Bundle;

import android.os.Handler;

import android.view.View;

import android.widget.Button;

import android.widget.ProgressBar;

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 MainActivity extends AppCompatActivity {

ProgressDialog pd;

Handler handler=new Handler();

Button b;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

EdgeToEdge.enable(this);

setContentView(R.layout.activity_main);

b=findViewById(R.id.btn);

b.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View view) {

pd=new ProgressDialog(MainActivity.this);

pd.setTitle("Downloading...");

pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

pd.setMax(100);

pd.setCancelable(false);

pd.show();

simulateProgress();

});

private void simulateProgress() {

new Thread(()->{

for(int progress=0;progress<=100;progress+=10){

int finalprogress=progress;

handler.post(()->

pd.setProgress(finalprogress));

try {

Thread.sleep(500);

catch(InterruptedException e){

e.printStackTrace();
}

pd.dismiss();

}).start();

Output:

You might also like