Pages

About

Pages - Menu

Ads 468x60px

Social Icons

Main Menu

Featured Posts

Thursday 10 July 2014

Android Progress Bar Tutorial

progress bar,the main.xml code will be as shown bellow


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=
http://schemas.android.com/apk/res/android
   android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please wait"
android:layout_marginTop="100dp"
android:layout_marginLeft="90dp"
android:textAppearance="?android:attr/textAppearanceLarge" />

    <ProgressBar
android:id="@+id/progressbar_default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"/>
    <ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progressbar_Horizontal"
android:max="100" />
</LinearLayout>



Activity class file.

package com.androidituts.progress;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
public class ProgressbardemoActivity extends Activity
{
ProgressBar myProgressBar;
int myProgress = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

myProgressBar=(ProgressBar)findViewById(R.id.progressbar_Horizontal);
new Thread(myThread).start();
}

private Runnable myThread = new Runnable(){
@Override
public void run()
{
// TODO Auto-generated method stub
while (myProgress<100)
{
try
{
myHandle.sendMessage(myHandle.obtainMessage());
Thread.sleep(1000);
}
catch(Throwable t)
{ }
}
}

Handler myHandle = new Handler()
{

@Override
public void handleMessage(Message msg)
{
// TODO Auto-generated method stub
yProgress++;
myProgressBar.setProgress(myProgress);
}
};
};
}

0 comments:

Post a Comment

Followers