main.xml
<linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<textview android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/hello">
<progressbar android:id="@+id/progressbar_default" android:layout_height="wrap_content" android:layout_width="wrap_content">
<progressbar android:id="@+id/progressbar_Horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent" android:max="100">
</progressbar>
ProgrssBarActivity.java'
package com.ProgessBar;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
public class ProgessBarActivity extends Activity {
ProgressBar mProgressBar;
int myProgress = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mProgressBar = (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 < 0) {
try {
myHandle.sendMessage(myHandle.obtainMessage());
Thread.sleep(50);
} catch (Throwable e) {
// TODO: handle exception
}
}
}
Handler myHandle = new Handler() {
public void handleMessage(Message msg) {
myProgress++;
mProgressBar.setProgress(myProgress);
}
};
};
}
<linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<textview android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="@string/hello">
<progressbar android:id="@+id/progressbar_default" android:layout_height="wrap_content" android:layout_width="wrap_content">
<progressbar android:id="@+id/progressbar_Horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent" android:max="100">
</progressbar>
ProgrssBarActivity.java'
package com.ProgessBar;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
public class ProgessBarActivity extends Activity {
ProgressBar mProgressBar;
int myProgress = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mProgressBar = (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 < 0) {
try {
myHandle.sendMessage(myHandle.obtainMessage());
Thread.sleep(50);
} catch (Throwable e) {
// TODO: handle exception
}
}
}
Handler myHandle = new Handler() {
public void handleMessage(Message msg) {
myProgress++;
mProgressBar.setProgress(myProgress);
}
};
};
}
No comments:
Post a Comment