Pls Help - Can't dismiss() ProgressDialog

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Pls Help - Can't dismiss() ProgressDialog

Postby jim3628 » Sun Mar 08, 2009 7:57 pm

Please help. I can't get this ProgressDialog to dismiss();

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         setContentView(R.layout.main);
  3.  
  4.         PDialog = ProgressDialog.show(HHDConvert.this,      
  5.  
  6.                    "", "Please wait for screen to load", true, true);
  7.  
  8.         // I dismiss() it immediately until I'm ready to show() it
  9.  
  10.         PDialog.dismiss();
  11.  
  12.  
  13.  
  14.         // ...
  15.  
  16.         // Buttons and listeners created here
  17.  
  18.                ...
  19.  
  20.  
  21.  
  22.         final ImageButton someButton10 = (ImageButton) findViewById(R.id.calorieButton10);
  23.  
  24.         someButton10.setOnClickListener(new View.OnClickListener() {
  25.  
  26.                 public void onClick(View v) {
  27.  
  28.  
  29.  
  30.                         // I found that the only way for me to show() the ProgressDialog
  31.  
  32.                         // was to create this Thread.
  33.  
  34.                         // PDialog.show(); did not work on it's own
  35.  
  36.                         Thread t = new Thread(new Runnable() {
  37.  
  38.                                 public void run() {
  39.  
  40.                                 Looper.prepare();
  41.  
  42.                                 PDialog.show();
  43.  
  44.                                 Looper.loop();
  45.  
  46.                         }
  47.  
  48.                         }); t.start();
  49.  
  50.  
  51.  
  52.                         // This method immediately calls: setContentView(R.layout.convxml);
  53.  
  54.                         // and creates many buttons in a LinerLayout and can take two seconds.
  55.  
  56.                         new_layout_of_Buttons(calorienum, caloriestr, caloriedouble);
  57.  
  58.        
  59.  
  60.                          // It all works very well until I try to dismiss() PDialog
  61.  
  62.                         PDialog.dismiss();
  63.  
  64.  
  65.  
  66.                 } // End of onClick
  67.  
  68.         }); // End of setOnClickListener
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


I think it has something to do with creating the ProgressDialog in one setContextView(main) and then trying to dismiss() it in the second setContextView(convxml), but I'm stumped.
Thanks in advance.
jim3628
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Mar 06, 2009 1:10 am

Top

Re: Pls Help - Can't dismiss() ProgressDialog

Postby sarangkulkarni17 » Mon Mar 09, 2009 11:07 am

jim3628 wrote:Please help. I can't get this ProgressDialog to dismiss();

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         setContentView(R.layout.main);
  2.         PDialog = ProgressDialog.show(HHDConvert.this,      
  3.                    "", "Please wait for screen to load", true, true);
  4.         // I dismiss() it immediately until I'm ready to show() it
  5.         PDialog.dismiss();
  6.  
  7.         // ...
  8.         // Buttons and listeners created here
  9.                ...
  10.  
  11.         final ImageButton someButton10 = (ImageButton) findViewById(R.id.calorieButton10);
  12.         someButton10.setOnClickListener(new View.OnClickListener() {
  13.                 public void onClick(View v) {
  14.  
  15.                         // I found that the only way for me to show() the ProgressDialog
  16.                         // was to create this Thread.
  17.                         // PDialog.show(); did not work on it's own
  18.                         Thread t = new Thread(new Runnable() {
  19.                                 public void run() {
  20.                                 Looper.prepare();
  21.                                 PDialog.show();
  22.                                 Looper.loop();
  23.                         }
  24.                         }); t.start();
  25.  
  26.                         // This method immediately calls: setContentView(R.layout.convxml);
  27.                         // and creates many buttons in a LinerLayout and can take two seconds.
  28.                         new_layout_of_Buttons(calorienum, caloriestr, caloriedouble);
  29.        
  30.                          // It all works very well until I try to dismiss() PDialog
  31.                         PDialog.dismiss();
  32.  
  33.                 } // End of onClick
  34.         }); // End of setOnClickListener
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


I think it has something to do with creating the ProgressDialog in one setContextView(main) and then trying to dismiss() it in the second setContextView(convxml), but I'm stumped.
Thanks in advance.


Try this code i think it will work
ProgressDialog myProgressDialog = null;


myProgressDialog = ProgressDialog.show(ClassName.this,
"Please wait...", "", true);
final Handler mHandler = new Handler() {
public void handleMessage(Message msg)
{

myProgressDialog.dismiss();

}
};
Thread.sleep(1000);
mHandler.sendEmptyMessage(1);
sarangkulkarni17
Developer
Developer
 
Posts: 29
Joined: Fri Feb 13, 2009 10:00 am
Location: Pune

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests