0% found this document useful (0 votes)
4 views

Rectangular_ProgressBar

The document contains an XML layout file and a Java activity class for an Android application. The layout features a horizontal progress bar and a text view to display progress percentage. The Java class updates the progress bar and text view in a separate thread, incrementing the progress status until it reaches 100%.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Rectangular_ProgressBar

The document contains an XML layout file and a Java activity class for an Android application. The layout features a horizontal progress bar and a text view to display progress percentage. The Java class updates the progress bar and text view in a separate thread, incrementing the progress status until it reaches 100%.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

activity_main.

xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">

<ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/progressText"
android:text="Progress: 0%"
android:textSize="18sp"
android:layout_marginTop="16dp" />
</LinearLayout>

MainActivity.java

package com.example.yourappname;

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

public class MainActivity extends AppCompatActivity {

private int progressStatus = 0;


private ProgressBar progressBar;
private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

progressBar = findViewById(R.id.progressBar);
textView = findViewById(R.id.textView);

new Thread(new Runnable() {


public void run() {
while (progressStatus < 100) {
progressStatus += 1;
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus + "/" +
progressBar.getMax());
}
});
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}

You might also like