android progressBar problem
Posted
by
kostas
on Stack Overflow
See other posts from Stack Overflow
or by kostas
Published on 2011-01-28T23:06:12Z
Indexed on
2011/01/28
23:26 UTC
Read the original article
Hit count: 210
android
hi.i have a button that on click is loading rss feed.i want to load a progress bar until my list opens.i have created a progressbar,it works,but as i press the return button to return to the main menu the progress bar appears again and it doesnt stop(and not even let me see my menu).this is my code
ProgressBar myProgressBar;
int myProgress = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main1);
Button nea = (Button) findViewById(R.id.nea);
nea.setOnClickListener(new View.OnClickListener() {
public void onClick (View view) {
setContentView(R.layout.bar);
myProgressBar=(ProgressBar)findViewById(R.id.bar);
new Thread(myThread).start();
Intent myIntent = new Intent(view.getContext(), nea.class);
startActivityForResult(myIntent, 0);
}
});
}
and then,out of the onCreate
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(){
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
myProgress++;
myProgressBar.setProgress(myProgress);
}
};
};
© Stack Overflow or respective owner