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

Practical No - 13

Practial no_14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Practical No - 13

Practial no_14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

“Program To Implement Horizontal Progress Bar”

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:weightSum="10">

<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/progress"
android:layout_marginTop="150sp"
style="@style/Widget.AppCompat.ProgressBar.Horizontal" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="75sp"
android:text="Start"
android:textSize="25sp"
android:id="@+id/btn"/>
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
ProgressBar pb;
int prog = 0;
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

pb = findViewById(R.id.progress);
bt = findViewById(R.id.btn);

bt.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
startProgress();
}
});
}
public void startProgress(){
prog=0;
pb.setProgress(prog);
Thread t = new Thread(new Runnable(){
@Override
public void run(){
while(prog<100){
try{
Thread.sleep(1000);
}catch(Exception e){
e.printStackTrace();
}
prog = prog + 10;
pb.setProgress(prog);
if(prog==100){
Toast.makeText(MainActivity.this,"Completed",Toast.LENGTH_LONG).show();
}
}
}
});
t.start();
}
}

You might also like