Sunday, October 20, 2019

One ProgressBar for whole Project .

ProgressBar can be used in whole Project by creating a single class.THis is demonstrated By the following code...


XML for ProgressBar...

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
 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:layout_width="wrap_content"       
 android:layout_height="wrap_content"      
 android:id="@+id/progressbar"      
 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintLeft_toLeftOf="parent"     
 app:layout_constraintRight_toRightOf="parent"       
 app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>



Java File


package com.a.progressbaee;

import android.app.Dialog;
import android.content.Context;

public class ProgressBar extends Dialog {
    public ProgressBar(Context context) {
        super(context);
        setContentView(R.layout.activity_main);

    }

    @Override    public void show() {
        super.show();
    }

    @Override    public void hide() {
        super.hide();
    }

    @Override    public void dismiss() {
        super.dismiss();
    }

    @Override    public void cancel() {
        super.cancel();
    }
}



This can be called in other classes By just 

providing the progressbar class name and creating its object..

ProgressBar progressbar;


TO show progressbar

progressbar.show();


To hide the progressbar

progressbar.hide();

To dismiss the Progrressbar

progressbar.dismiss();

To cancel the progressbar

progressbar.cancel();




No comments:

Alert Dialog Box

Alert Dialog Box Android AlertDialog   can be used to display the dialog message with OK and Cancel buttons. It can be used to inter...