For 5000ms I m showing a dialog box After dismissal of my dialog-box, toast should appear but its not, why I m not getting this?how can I do this?
Help is always appreciated..!
signin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// showDialog(0);
t = new Thread() {
public void run() {
register();
try {
开发者_StackOverflow社区 while(counter<1){
showmsg(0);
Thread.sleep(5000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
t.start();
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0: {
++counter;
dialog = new ProgressDialog(this);
if(counter==1){
dialog.setMessage("Registering...");
}
else{
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
dialog.setIndeterminate(true);
dialog.setCancelable(true);
return dialog;
}
}
return null;
}
public void showmsg(int actionsToBePerformedOnScreen) {
Message msg = new Message();
msg.what = actionsToBePerformedOnScreen;
handler.sendMessage(msg);
}
public Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
showDialog(0);
break;
case 1:
// clear all images in the list
removeDialog(0);
break;
}
};
};
You are trying to show your Toast in onCreateDialog
method and it's conditioned on counter!=1
. onCreateDialog
is not called when you show dialog but only when you create it. It's only called once so Toast never appear.
I believe that you are trying to run the thread, show progress when it's running and dismiss it and show Toast when it's complete. If that's the case, much simpler and correct way to achieve your goal is to use AsyncTask
. Read about it here: http://developer.android.com/reference/android/os/AsyncTask.html
Feel free to ask more questions.
精彩评论