0% found this document useful (0 votes)
21 views1 page

13 mad

The document outlines an Android application that implements a progress bar for file downloading. It includes XML layout for a button and Java code to manage the progress dialog and simulate file download progress. The application updates the progress bar status in a separate thread until the download is complete.

Uploaded by

Pratiksha Wagh
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)
21 views1 page

13 mad

The document outlines an Android application that implements a progress bar for file downloading. It includes XML layout for a button and Java code to manage the progress dialog and simulate file download progress. The application updates the progress bar status in a separate thread until the download is complete.

Uploaded by

Pratiksha Wagh
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/ 1

Practical no 13

<RelativeLayout xmlns:androclass="http:// while (progressBarStatus < 100


schemas.android.com/apk/res/android" ){
xmlns:tools="http://schemas.android.com/tools" progressBarStatus = doOper
android:layout_width="match_parent" ation();
android:layout_height="match_parent" try {
tools:context=".MainActivity" > Thread.sleep(1000);
<Button } catch (InterruptedExceptio
android:id="@+id/button1" n e) {
android:layout_width="wrap_content" e.printStackTrace();
android:layout_height="wrap_content" }
android:layout_alignParentTop="true" progressBarHandler.post(ne
android:layout_centerHorizontal="true" w Runnable() {
android:layout_marginTop="116dp" public void run() {
android:text="download file" /> progressBar.setProgress(
</RelativeLayout> progressBarStatus);
} });
package example.com.progressbar; }
import android.app.ProgressDialog; if (progressBarStatus >= 100) {
import android.os.Handler; try {
import android.support.v7.app.AppCompatAc Thread.sleep(1000);
tivity; } catch (InterruptedExceptio
import android.os.Bundle; n e) {
import android.view.View; e.printStackTrace();
import android.widget.Button; }
public class MainActivity extends AppCompa // close the progress bar dialo
tActivity { g
Button btnStartProgress; progressBar.dismiss();
ProgressDialog progressBar; }
private int progressBarStatus = 0; }
private Handler progressBarHandler = new }).start();
Handler(); });
private long fileSize = 0; }
@Override public int doOperation() {
protected void onCreate(Bundle savedInsta while (fileSize <= 10000) {
nceState) { fileSize++;
super.onCreate(savedInstanceState); if (fileSize == 1000) {
setContentView(R.layout.activity_main); return 10;
addListenerOnButtonClick(); } } else if (fileSize == 2000) {
public void addListenerOnButtonClick() { return 20;
btnStartProgress = findViewById(R.id.bu } else if (fileSize == 3000) {
tton); return 30;
btnStartProgress.setOnClickListener(new } else if (fileSize == 4000)
View.OnClickListener(){ return 40;
@Override }
public void onClick(View v) { else { return 100;
progressBar = new ProgressDialog(v }
.getContext()); } return 100;
progressBar.setCancelable(true); }}
progressBar.setMessage("File downl
oading ...");
progressBar.setProgressStyle(Progre
ssDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
progressBarStatus = 0;
fileSize = 0;
new Thread(new Runnable() {
public void run() {

You might also like