Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. MainActivity{
  2.  
  3. Dialog dialog;
  4. ProgressDialog progress;
  5.  
  6. onCreate(){
  7. dialog = new Dialog(this);
  8. progress = new ProgressDialog(this);
  9. dialog.setContentView(Some View Resource With My Button);
  10. someMethod();
  11. dialog.show();
  12. }
  13.  
  14. someMethod(){
  15. Button button = (Button) dialog.findViewById(resource of button);
  16. button.setOnClickListener(new OnClickListener(){
  17.  
  18. onClick(){
  19. dialog.dismiss();
  20. progress.show();
  21. new DownloaderAsyncTask(progress).execute().get();
  22. }
  23.  
  24. //go to another activity when download finished
  25.  
  26. });
  27. }
  28.  
  29. private class DownloaderAsyncTask extends AsyncTask<Void, Void, Void>{
  30.  
  31. ProgressDialog progress;
  32.  
  33. DownloaderAsyncTask(ProgressDialog progress){
  34. this.progress = progress;
  35. }
  36.  
  37. doInBackGround(){
  38. //Downloading
  39. }
  40.  
  41. onPostExecute(){
  42. //Kill connection
  43. this.progress.dismiss();
  44. }
  45.  
  46. }
  47.  
  48. }
  49.  
  50. new DownloaderAsyncTask(progress).execute().get();
  51.  
  52. someMethod() {
  53. Button button = (Button) dialog.findViewById(resource of button);
  54. button.setOnClickListener(new OnClickListener(){
  55.  
  56. onClick(){
  57. dialog.dismiss();
  58. progress.show();
  59. new DownloaderAsyncTask().execute();
  60. }
  61. });
  62.  
  63. private void downloaderFinished() {
  64. this.progress.dismiss();
  65. /// go to next activity.
  66. }
  67.  
  68. private class DownloaderAsyncTask extends AsyncTask<Void, Void, Void>{
  69.  
  70. doInBackGround(){
  71. //Downloading
  72. }
  73.  
  74. onPostExecute(){
  75. //Kill connection
  76. downloaderFinished();
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement