My app contained download button and whenever that button is pressed, I want some Progress Bar to show up so that the user knows there is something happening. What I really want to do is, whenever the Progress Bar is finished, I want some Toast to pop out. Can some one guide me with this? I would really appreciate it a lot. Thanks in advance!
Here is the code I am using:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ProgressDialog dialog = new ProgressDialog(MyActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMessage("Downloading...");
dialog.setCancelable(true);
dialog.setMax(200);
dialog.setProgress(0);
dialog.show();
Thread t = new Thread(new Runnable(){
public void run() {
while(dialog.getProgress() < dialog.getMax())
{
dialog.incrementProgressBy(1);
try{Thread.sleep(50);}catch(Exception e){/* no-op */}
}
dialog.dismiss();
}
});
t.start();
}
AsyncTask would be the easiest but if you are adamant on using your code you can add this snippet after the dialog.dismiss() statement.
This is because the Toast must only be shown on the UI Thread.