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

Mad Practical 13

The document provides XML and Java code for a simple Android application that includes a progress dialog for file downloading. It demonstrates the layout with a ProgressBar and a Button that initiates the download process. The Java code manages the progress of the download and updates the UI accordingly.

Uploaded by

Nawaz Wariya
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)
11 views2 pages

Mad Practical 13

The document provides XML and Java code for a simple Android application that includes a progress dialog for file downloading. It demonstrates the layout with a ProgressBar and a Button that initiates the download process. The Java code manages the progress of the download and updates the UI accordingly.

Uploaded by

Nawaz Wariya
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/ 2

MAD(22617) Practical code Practical 13

XML CODE: Output:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.co
m/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
XML CODE:
JAVA CODE: <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
package com.example.practical;
xmlns:android="http://schemas.android.co
import android.os.Bundle;
m/apk/res/android"
import
android:layout_width="match_parent"
androidx.appcompat.app.AppCompatActi
android:layout_height="match_parent"
vity;
android:gravity="center"
public class MainActivity extends
android:orientation="vertical"
AppCompatActivity {
android:padding="20dp">
@Override
<Button
protected void onCreate(Bundle
android:id="@+id/search_go_btn"
savedInstanceState) {
android:layout_width="wrap_content"
super.onCreate(savedInstanceState);
android:layout_height="wrap_content"
setContentView(R.layout.activity_main);
android:text="DOWNLOAD FILE"/>
}
</LinearLayout>
}

JAVA CODE:
package com.example.practical;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

1|Page
MAD(22617) Practical code Practical 13

import android.widget.Button; progressDialog.setProgress(progress));


import try {
androidx.appcompat.app.AppCompatActi Thread.sleep(500); // Simulate
vity; download time
public class MainActivity extends } catch (InterruptedException e) {
AppCompatActivity { e.printStackTrace();
private ProgressDialog progressDialog; }
private int progress = 0; }
private Handler handler = new progressDialog.dismiss();
Handler(); }).start();
@Override }
protected void onCreate(Bundle }
savedInstanceState) {
super.onCreate(savedInstanceState); Output:
setContentView(R.layout.activity_main);
Button btnDownload =
findViewById(R.id.search_go_btn);
btnDownload.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
showProgressDialog();
}
});
}
private void showProgressDialog() {
progressDialog = new
ProgressDialog(MainActivity.this);
progressDialog.setTitle("File
downloading ...");
progressDialog.setProgressStyle(ProgressD
ialog.STYLE_HORIZONTAL);
progressDialog.setMax(100);
progressDialog.setProgress(0);
progressDialog.setCancelable(false);
progressDialog.show();
new Thread(() -> {
while (progress < 100) {
progress += 10;
handler.post(() ->

2|Page

You might also like