Practical 13
Practical 13
Exercise :-
Output :-
2). Write a program to show the following output.
Code :-
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.co m/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;
public class MainActivity extends AppCompatActivity
{
Button btnDownloadFile;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnDownloadFile = findViewById(R.id.btnDownloadFile);
btnDownloadFile.setOnClickListener(new View.OnClickListener())
{
@Override
public void onClick(View v)
{
progressDialog = newProgressDialog (MainActivity.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
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 :-