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

Practical No 13

The document outlines methods for updating progress displays in Android applications, including XML attributes for progress bars and various styles available. It provides example code for implementing a circular progress bar and a download progress bar using Java and XML layouts. Additionally, it details the structure of the required XML files for the progress bars and their associated drawable resources.

Uploaded by

pirofa8256
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)
29 views8 pages

Practical No 13

The document outlines methods for updating progress displays in Android applications, including XML attributes for progress bars and various styles available. It provides example code for implementing a circular progress bar and a download progress bar using Java and XML layouts. Additionally, it details the structure of the required XML files for the progress bars and their associated drawable resources.

Uploaded by

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

Mobile Application Development (22617) Ms. Batule P.

Practical No.13

Q.1) State different methods to update the percentage of progress


display.

ANS— To update the percentage of progress displayed in Android, you can use
the following attributes in the XML layout file:

 android:max: Sets the maximum value of the progress bar. The default value is
100.
 android:indeterminate: A boolean value that determines whether the progress
bar shows the actual progress or a cyclic animation. Set to false to show the
actual progress, or true to display a cyclic animation.
 android:progress: Sets the number by which the progress bar value will be
incremented.
 style: Sets the display of the progress bar. The default is a spinning wheel, but
you can set it to a horizontal bar by using the
attribute style=“? android:attr/progressBarStyleHorizontal”.
You can also create a progress bar in an Android app by adding
a <ProgressBar> element to the XML layout file.

Q.2) Write an XML tag for the determinate progress bar.

ANS— <ProgressBar
android:id="@+id/idPBLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/idBtnDisplayProgress"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:visibility="gone" />

Q.3) List different progress bar styles provided by the system.

ANS— Here are some different progress bar styles available in Android:
Mobile Application Development (22617) Ms. Batule P.S

 Indeterminate
Used when the progress information is unclear, the loading progress is
unknown, or the waiting time is incalculable
 Circular
An animated indicator moves along an invisible circular track in a clockwise
direction. This type of progress bar can be applied to a surface, such as a button
or card.
 Horizontal
A horizontal line that grows from left to right as the progress increases
 Linear
An indicator animates along a fixed, visible track to display progress. This type of
progress bar supports both determinate and indeterminate operations

Q.4) Write the program to display circular progress bar

ANS— MainActivity.java:

package com.blogspot.codingatharva.manualprograms;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {


Button b;

ProgressBar pb;

private int progressStatus = 0;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

b = findViewById(R.id.btn);
Mobile Application Development (22617) Ms. Batule P.S

pb = findViewById(R.id.progressBar);

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

startProgress(v);

}
});
}
public void startProgress(View view) {

pb.setProgress(0);

new Thread(new Task()).start();

}
class Task implements Runnable {

@Override

public void run() {

for (int i = 0; i <= 10; i++) {

final int value = i;

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();
}

pb.setProgress(value);

} }}
}
activity_main.xml:
<div style="white-space: normal; height: auto; visibility: visible; font-
size: 14px;">

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

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

xmlns:tools = "http://schemas.android.com/tools"
Mobile Application Development (22617) Ms. Batule P.S

android:layout_width= "match_parent"

android:layout_height= "match_parent"

android:layout_margin= "16dp"

tools:context= ".MainActivity" >

<ProgressBar

android:id= "@+id/progressBar"

style= "?android:attr/progressBarStyleHorizontal"

android:layout_width= "200dp"

android:layout_height= "200dp"

android:layout_centerInParent= "true"

android:background= "@drawable/circular_shape"

android:indeterminate= "false"

android:max= "100"

android:progress= "0"

android:progressDrawable= "@drawable/circular_progress_bar" />

<Button

android:id="@+id/btn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:layout_below="@+id/progressBar"

android:text="Start"/>

</RelativeLayout></div>

circular_progress_bar.xml: under res/drawable


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

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

android:fromDegrees= "270"

android:toDegrees= "270" >


Mobile Application Development (22617) Ms. Batule P.S

<shape

android:innerRadiusRatio= "2.5"

android:shape= "ring"

android:thickness= "1dp"

android:useLevel= "true" > <!-- this line fixes the issue for
lollipop api 21 -->

<gradient

android:angle= "0"

android:endColor= "#007DD6"

android:startColor= "#007DD6"

android:type= "sweep"

android:useLevel= "false" />

</shape>

</rotate>

circular_shape.xml: under res/drawable


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

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

android:innerRadiusRatio= "2.5"

android:shape= "ring"

android:thickness= "1dp"

android:useLevel= "false" >

<solid android:color= "#CCC" />

</shape>

Q.5) Write the program to show the following output.

ANS-- MainActivity.java:

package com.example.mad;

import android.os.Bundle;

import android.os.Handler;
Mobile Application Development (22617) Ms. Batule P.S

import android.os.Looper;

import android.view.View;

import android.widget.Button;

import android.widget.ProgressBar;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

public class MainActivity extends AppCompatActivity {

private ProgressBar downloadProgressBar; private Button


downloadButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

downloadProgressBar = findViewById(R.id.downloadProgressBar);

downloadButton = findViewById(R.id.downloadButton);

public void startDownload(View view) {

// Show the progress bar

downloadProgressBar.setVisibility(ProgressBar.VISIBLE);

downloadButton.setEnabled(false);

final Handler handler = new Handler(Looper.getMainLooper());

handler.postDelayed(new Runnable() {

int progress = 0;

@Override

public void run() {

progress += 5;

downloadProgressBar.setProgress(progress);
Mobile Application Development (22617) Ms. Batule P.S

if (progress < 100) {

handler.postDelayed(this, 500);

else {

downloadProgressBar.setVisibility(ProgressBar.GONE);

downloadButton.setEnabled(true);

}}

},500);

}}

activity_main.xml
<RelativeLayout

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<Button android:id="@+id/downloadButton"

android:layout_width="wrap_content" a

ndroid:layout_height="wrap_content"

android:layout_centerInParent="true"

android:text="Download File"

android:onClick="startDownload"/>

<ProgressBar android:id="@+id/downloadProgressBar"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/downloadButton"
Mobile Application Development (22617) Ms. Batule P.S

android:layout_marginTop="20dp"

android:indeterminate="false"

android:visibility="gone"/>

</RelativeLayout>

You might also like