Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainActivity{
- Dialog dialog;
- ProgressDialog progress;
- onCreate(){
- dialog = new Dialog(this);
- progress = new ProgressDialog(this);
- dialog.setContentView(Some View Resource With My Button);
- someMethod();
- dialog.show();
- }
- someMethod(){
- Button button = (Button) dialog.findViewById(resource of button);
- button.setOnClickListener(new OnClickListener(){
- onClick(){
- dialog.dismiss();
- progress.show();
- new DownloaderAsyncTask(progress).execute().get();
- }
- //go to another activity when download finished
- });
- }
- private class DownloaderAsyncTask extends AsyncTask<Void, Void, Void>{
- ProgressDialog progress;
- DownloaderAsyncTask(ProgressDialog progress){
- this.progress = progress;
- }
- doInBackGround(){
- //Downloading
- }
- onPostExecute(){
- //Kill connection
- this.progress.dismiss();
- }
- }
- }
- new DownloaderAsyncTask(progress).execute().get();
- someMethod() {
- Button button = (Button) dialog.findViewById(resource of button);
- button.setOnClickListener(new OnClickListener(){
- onClick(){
- dialog.dismiss();
- progress.show();
- new DownloaderAsyncTask().execute();
- }
- });
- private void downloaderFinished() {
- this.progress.dismiss();
- /// go to next activity.
- }
- private class DownloaderAsyncTask extends AsyncTask<Void, Void, Void>{
- doInBackGround(){
- //Downloading
- }
- onPostExecute(){
- //Kill connection
- downloaderFinished();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement