Exp 13
Exp 13
2
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btnDownloadFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Download File"
android:layout_centerInParent="true"/>
</RelativeLayout>
JAVA CODE
package com.example.progrogress;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZ
ONTAL);
progressDialog.setTitle("File
Downloading");
progressDialog.setProgress(100);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
int progress = 0;
while (progress <=100){
try {
progressDialog.setProgress(progress);
progress++;
Thread.sleep(200);
}catch (Exception ex){
}
}
progressDialog.dismiss();
}
});
t.start();
progressDialog.show();
}
});
}
}
OUTPUT
EXTRA
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com
/apk/res/android"
xmlns:app="http://schemas.android.com/apk
/res-auto"
xmlns:tools="http://schemas.android.com/t
ools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/pb2"
android:progress="00"
android:layout_width="200dp"
android:layout_height="150dp"
style="?
android:progressBarStyleHorizontal"
android:layout_centerInParent="true"
/>
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/pb2"
android:layout_centerHorizontal="true"
android:text="Start"
android:layout_marginTop="50dp"/>
</RelativeLayout>
package com.example.exp13;
import
androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// pb1 = findViewById(R.id.pb1);
pb2 = findViewById(R.id.pb2);
btn1 = findViewById(R.id.btn1);
btn1.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
while(progress !=100) {
progress
= progress + 5;
//
pb1.setProgress(progress);
pb2.setProgress(progress);
Thread.sleep(200);
}
}
catch
(InterruptedException e){
e.printStackTrace();
}
}
});
thread.start();
}
});
}
}