[android-developers] Progress bar with threads
Hi all,
I'm writing an application for uploading a file to server, the
uploading status should be shown with the Progress bar. I've used
threads to display the completion status of the uploading process.
I'm not posting my code because its confidential, i'm posting a sample
code which resembles my problem in which i'm trying to print some
numbers in one thread and displaying the progress bar in another
thread. But it is not working when i remove the while loop in the
first run method, the Progress bar is not showing the status, but if i
don't remove that loop the numbers are being printed repeatedly for
100 times.
Here is my code so please come up with your suggestions, its urgent.
Thanks in advance
Kitty
PBar.java
public class Pbar extends Activity {
int progress=0;
ProgressBar pbar;
int progressStatus=0;
Handler handler=new Handler();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pbar=(ProgressBar)findViewById(R.id.progressbar);
new Thread(new Runnable()
{
public void run()
{
while(progressStatus < 100)
{
progressStatus=method();
System.out.println("PS---->"+progressStatus);
handler.post(new Runnable()
{
public void run()
{
pbar.incrementProgressBy(10);
}
});
}
handler.post(new Runnable()
{
public void run()
{
pbar.setVisibility(8);
}
});
}
private int method()
{
try
{
sample();
Thread.sleep(500);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
return ++progress;
}
}).start();
}
public void sample()
{
for(int i=0;i<100;i++)
{
System.out.println("i----->"+i);
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home