0% found this document useful (0 votes)
16 views5 pages

Pra 13 EX

The document contains XML layout and Java code for an Android application that implements a horizontal progress bar and a cyclic progress bar. The main activity updates the horizontal progress bar's value in a background thread while displaying the current progress in a TextView. The layout is designed using RelativeLayout, and the progress bar is set to a maximum of 100 with a defined increment in the background thread.

Uploaded by

sammedmohare465
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)
16 views5 pages

Pra 13 EX

The document contains XML layout and Java code for an Android application that implements a horizontal progress bar and a cyclic progress bar. The main activity updates the horizontal progress bar's value in a background thread while displaying the current progress in a TextView. The layout is designed using RelativeLayout, and the progress bar is set to a maximum of 100 with a defined increment in the background thread.

Uploaded by

sammedmohare465
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/ 5

Pra:13

Ex:Q.1

<?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">

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:max="100"
android:minHeight="50dp"
android:minWidth="200dp"
android:progress="1" />

<ProgressBar
android:id="@+id/progressBar_cyclic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:minWidth="50dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar"
android:layout_below="@+id/progressBar"/>

</RelativeLayout>
package com.example.circularprogressbar;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private ProgressBar progressBar;


private int progressStatus = 0;
private TextView textView;
private Handler handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

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


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

// Start long running operation in a background thread


new Thread(new Runnable() {

public void run() {

while (progressStatus < 100) {

progressStatus += 1;
// Update the progress bar and display the
//current value in the text view

handler.post(new Runnable() {

public void run() {

progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});

try {
Thread.sleep(200);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}

Q.2

<?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">

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:max="100"
android:minHeight="50dp"
android:minWidth="200dp"
android:progress="1" />

<ProgressBar
android:id="@+id/progressBar_cyclic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:minWidth="50dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar"
android:layout_below="@+id/progressBar"/>

</RelativeLayout>

package com.example.circularprogressbar;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private ProgressBar progressBar;


private int progressStatus = 0;
private TextView textView;
private Handler handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

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


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

// Start long running operation in a background thread


new Thread(new Runnable() {

public void run() {

while (progressStatus < 100) {

progressStatus += 1;
// Update the progress bar and display the
//current value in the text view

handler.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