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

Pract12 13

The document contains XML layout code for an Android application, defining a user interface with radio buttons, a progress bar, and a button to download a file. It also includes Java code for the MainActivity class, which manages the button click event to show a progress dialog during a simulated file download. The layout uses ConstraintLayout and various UI components to create an interactive experience for the user.

Uploaded by

harshdpatil445
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 views3 pages

Pract12 13

The document contains XML layout code for an Android application, defining a user interface with radio buttons, a progress bar, and a button to download a file. It also includes Java code for the MainActivity class, which manages the button click event to show a progress dialog during a simulated file download. The layout uses ConstraintLayout and various UI components to create an interactive experience for the user.

Uploaded by

harshdpatil445
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/ 3

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

> android:layout_height="wrap_content"
<androidx.constraintlayout.widget.Constra android:text="Male" />
intLayout <RadioButton
xmlns:android="http://schemas.android.com android:id="@+id/female"
/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk android:text="Female" />
/res-auto" </RadioGroup>
<Button
xmlns:tools="http://schemas.android.com/t android:id="@+id/buttons"
ools"
android:id="@+id/main" android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
tools:context=".MainActivity"> android:translationY="350dp"
android:translationX="140dp"
<TextView android:text="SHOW SELECTED" />
android:id="@+id/textView1" </androidx.constraintlayout.widget.Constr
aintLayout>
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:translationX="110dp"
android:translationY="40dp"
android:textSize="20sp"
android:text="Single Radio
Buttons" />
<RadioButton
android:id="@+id/rb1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:translationY="100dp"
android:text="RadioButton1" />

<RadioButton
android:id="@+id/rb2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:translationY="130dp"
android:text="RadioButton2" />
<TextView
android:id="@+id/textView2"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationX="60dp"
android:translationY="200dp"
android:textSize="20sp"
android:text="Radio button inside
RadioGroup" />
<RadioGroup
android:id="@+id/radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationY="250dp">
<RadioButton
android:id="@+id/male"
android:layout_width="match_parent"
1No 2No

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


<androidx.constraintlayout.widget.Constra <?xml version="1.0" encoding="utf-8"?>
intLayout <androidx.constraintlayout.widget.Constra
xmlns:android="http://schemas.android.com intLayout
/apk/res/android" xmlns:android="http://schemas.android.com
xmlns:app="http://schemas.android.com/apk /apk/res/android"
/res-auto" xmlns:app="http://schemas.android.com/apk
xmlns:tools=http://schemas.android.com/to /res-auto"
ols android:id="@+id/main" xmlns:tools="http://schemas.android.com/t
android:layout_width="match_parent" ools"
android:layout_height="match_parent" android:id="@+id/main"
tools:context=".MainActivity"> android:layout_width="match_parent"
<ProgressBar android:layout_height="match_parent"
android:id="@+id/progressBar" tools:context=".MainActivity">
style="?android:attr/progressBarStyle" <Button
android:layout_width="196dp" android:id="@+id/b"
android:layout_height="185dp" android:layout_width="wrap_content"
android:translationX="100dp" android:layout_height="wrap_content"
android:translationY="250dp" android:text="Download File"
tools:layout_editor_absoluteX="117dp" app:layout_constraintBottom_toBottomOf="p
tools:layout_editor_absoluteY="245dp" /> arent"
<TextView android:id="@+id/textView" app:layout_constraintLeft_toLeftOf="paren
android:layout_width="wrap_content" t"
android:layout_height="wrap_content" app:layout_constraintRight_toRightOf="par
android:translationY="480dp" ent"
android:translationX="150dp" app:layout_constraintTop_toTopOf="parent"
android:textStyle="italic" />
android:textSize="30sp" </androidx.constraintlayout.widget.Constr
android:text="Loading..." /> aintLayout>
</androidx.constraintlayout.widget.Constr
aintLayout>
MainActivity.java

package com.harsh.pract13_2;
import android.os.Bundle;
import android.widget.Button;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import
androidx.core.view.WindowInsetsCompat;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
public class MainActivity extends
AppCompatActivity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
final Button
b=(Button)findViewById(R.id.b);
final ProgressDialog pd=new
ProgressDialog(MainActivity.this);
b.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
pd.setTitle("Downloading
file");

pd.setProgressStyle(ProgressDialog.STYLE_
HORIZONTAL);
pd.setMax(100);
pd.show();
new Thread(new Runnable()
{
@Override
public void run() {
try {
while
(pd.getProgress() <= pd.getMax()) {

Thread.sleep(2000);

h.sendMessage(h.obtainMessage());
if
(pd.getProgress() == pd.getMax()) {

pd.dismiss();
}
}
} catch
(InterruptedException e) {

e.printStackTrace();
}
}
}).start();
}
Handler h=new Handler()
{
@Override
public void
handleMessage(@NonNull Message msg) {

super.handleMessage(msg);

pd.incrementProgressBy(1);
}
};
});
}
}

You might also like