Android: Cannot dismiss progressdialog
I开发者_如何学Go am trying to dismiss a progress dialog but it doesnt seem to work for some reason. Any suggestions why is it so?? The progress dialog is initialized on button click and shows the dialog. The syncbutton method calls a thread which sends an empty message
thanks
mHandler.sendEmptyMessage(0);//from thread
Code for button click
public void onClick(View v) {
pd = new ProgressDialog(Screen.this);
pd.setCancelable(true);
ProgressDialog.show(Screen.this, "Sync", "Sync in progress",true,false);
SyncButton();
}
});
Code for message handler which should dismiss the progressbar
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
Log.d("Handler","handler");
if (Screen==true){
if (pd !=null)
{
pd.cancel();
pd.dismiss();
Log.d("HANDLER", "called dismiss");
}
}
}
};
PS: I did try using asynctask but was having problems with it. Thats why took this approach. I had posted that question here
Looke like you are creating one progress dialog here:
pd = new ProgressDialog(Screen.this);
pd.setCancelable(true);
That one isn't displayed. You create and display another one:
ProgressDialog.show(Screen.this, "Sync", "Sync in progress",true,false);
Remove the two first lines, and change your other line to:
pd = ProgressDialog.show(Screen.this, "Sync", "Sync in progress",true,false);
You aren't showing the pd you created, you are showing a new one.
build pd
pd.setTitle("Sync");
pd.setMessage("Sync in progress");
then use
pd.show();
精彩评论