Progress Bar Tutorial For Android

Purpose of Progress Bar

Progress Bar is used when app required some progressing behind or require some procesing which take time to show the user app is busy and will take time. Here is the source code to show progerss bar on android.

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:background="@drawable/splash" android:layout_height="fill_parent"
	android:layout_width="fill_parent">
	<LinearLayout android:layout_alignParentBottom="true"
		android:layout_centerHorizontal="true" android:layout_marginBottom="58px"
		android:layout_height="45px" android:layout_width="200px"
		android:id="@+id/lin_progress_bar" android:visibility="invisible">
		<ProgressBar android:id="@+id/ProgressBar01"
			android:layout_width="wrap_content" android:layout_height="wrap_content"></ProgressBar>
		<TextView android:id="@+id/TextView01" android:layout_height="fill_parent"
			android:layout_width="fill_parent" android:gravity="center_vertical"
			android:textStyle="bold" android:text="Loading..."
			android:layout_marginLeft="10px" android:textSize="23px"
			android:textColor="#808080"></TextView>
	</LinearLayout>
</RelativeLayout>

Progress Bar is used under the linear layout tag to simply hide and show the layout as required.
Splash.java

public class Splash extends Activity {

	private LinearLayout linProgressBar;
	private final Handler uiHandler=new Handler();
	private boolean isUpdateRequired=false;

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

		basicInitializations();
	}

	public void basicInitializations(){

		linProgressBar = (LinearLayout) findViewById(R.id.lin_progress_bar);
		linProgressBar.setVisibility(View.VISIBLE);

		try{
			new Thread(){
				public void run() {
					initializeApp();
					uiHandler.post( new Runnable(){
						@Override
						public void run() {
							if(isUpdateRequired){
								//TODO:
							}else{
								linProgressBar.setVisibility(View.GONE);
								startActivity( new Intent(WMXSplash.this, WMXLogin.class) );
								finish();
							}
						}
					} );
				}
				public void initializeApp(){
					// Initialize application data here
				}
		}.start();
		}catch (Exception e) {}
	}

Thread starts when processing starts and when processing completes dialog box dismissed and layout gone.

Loading Progress Bar

see the blog.   http://huuah.com/android-progress-bar-and-thread-updating/

About these ads
This entry was posted in Android, Tutorials and tagged , , , , . Bookmark the permalink.

One Response to Progress Bar Tutorial For Android

  1. sales tips says:

    It’s so lucky for me to find your!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s