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

Activity Main

The document contains an XML layout and Java code for an Android application that implements a progress bar. The MainActivity class initializes a ProgressBar and a TextView, updating the progress status in a separate thread. The progress is displayed as a percentage on the TextView while the ProgressBar visually represents the progress.

Uploaded by

Kolekar Yashraj
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)
12 views2 pages

Activity Main

The document contains an XML layout and Java code for an Android application that implements a progress bar. The MainActivity class initializes a ProgressBar and a TextView, updating the progress status in a separate thread. The progress is displayed as a percentage on the TextView while the ProgressBar visually represents the progress.

Uploaded by

Kolekar Yashraj
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

XML File

public class MainActivity extends


<?xml version="1.0" encoding="utf-8"?>
AppCompatActivity {
<LinearLayout
xmlns:android="http://schemas.android.com/
private ProgressBar progressBar;
apk/res/android"
private TextView progressText;
android:layout_width="match_parent"
private int progressStatus = 0;
android:layout_height="match_parent"
private Handler handler = new Handler();
android:gravity="center"
android:orientation="vertical"
@Override
android:padding="20dp">
protected void onCreate(Bundle
<TextView
savedInstanceState) {
android:layout_width="wrap_content"
super.onCreate(savedInstanceState);
android:layout_height="wrap_content"
setContentView(R.layout.activity_main);
android:text="Progress Bar"
android:textSize="30sp"
progressBar =
android:textStyle="italic|bold"/>
findViewById(R.id.progressBar);
progressText =
<ProgressBar
findViewById(R.id.progressText);
android:id="@+id/progressBar"
new Thread(() -> {
style="?android:attr/progressBarStyleHorizont
while (progressStatus < 100) {
al"
progressStatus += 1;
android:layout_width="200dp"
handler.post(() -> {
android:layout_height="wrap_content"
android:max="100"
progressBar.setProgress(progressStatus);
android:progress="0"
progressText.setText("Progress: " +
android:indeterminate="false" />
progressStatus + "%");
});
<TextView
try {
android:id="@+id/progressText"
Thread.sleep(100); // Simulate
android:layout_width="wrap_content"
progress update
android:layout_height="wrap_content"
} catch (InterruptedException e) {
android:layout_marginTop="20dp"
e.printStackTrace();
android:text="progress: 0%"
}
android:textSize="18sp"/>
}
</LinearLayout>
}).start();
ACTIVITY File }
}
package com.example.prac13;

import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;
import
androidx.appcompat.app.AppCompatActivity;

You might also like