Android:ProgressDialog 然后 toast
可能的重复:
Android:ProgressDialog.show() 使用 getApplicationContext 崩溃
我想要取得进展首先显示对话框,然后显示吐司。我希望只要用户选择的时间延迟(例如 15、30、60 秒)加载进度对话框,并且没有延迟,然后显示消息已发送的 toast。我该如何实施?我在哪里以及如何在我的代码上执行此操作?
这是我的代码:
btnSend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneNo = editTextRecipient.getText().toString();
String message = editTextNewMessage.getText().toString();
boolean split = false;
final Toast toast = Toast.makeText(getBaseContext(),
"Your message " + "\"" + message + "\"" + " is sent to " +"\""+ phoneNo+"\"",
Toast.LENGTH_SHORT);
Runnable showToastRunnable = new Runnable() {
public void run() {
toast.show();
// Send button Listener
}
};
if (phoneNo.length()>0 && message.length()>0) {
if (count == 0) {
handler.postDelayed(showToastRunnable, 0);
}
else if (count == 1) {
handler.postDelayed(showToastRunnable, 15000);
}
else if (count == 2) {
handler.postDelayed(showToastRunnable, 30000);
}
else if (count == 3) {
handler.postDelayed(showToastRunnable, 60000);
}
}
// sendSMS(phoneNo, message, split); */
else
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
});
}
Possible Duplicate:
Android: ProgressDialog.show() crashes with getApplicationContext
I want to have a progress dialog to show up first then the toast. I want the progress dialog to load as long as the time delay chosen by the user like 15, 30, 60 seconds and no delay then the toast indicating that the message has been sent. How can I implement it? Where and how do I do it on my code?
Here's my code:
btnSend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneNo = editTextRecipient.getText().toString();
String message = editTextNewMessage.getText().toString();
boolean split = false;
final Toast toast = Toast.makeText(getBaseContext(),
"Your message " + "\"" + message + "\"" + " is sent to " +"\""+ phoneNo+"\"",
Toast.LENGTH_SHORT);
Runnable showToastRunnable = new Runnable() {
public void run() {
toast.show();
// Send button Listener
}
};
if (phoneNo.length()>0 && message.length()>0) {
if (count == 0) {
handler.postDelayed(showToastRunnable, 0);
}
else if (count == 1) {
handler.postDelayed(showToastRunnable, 15000);
}
else if (count == 2) {
handler.postDelayed(showToastRunnable, 30000);
}
else if (count == 3) {
handler.postDelayed(showToastRunnable, 60000);
}
}
// sendSMS(phoneNo, message, split); */
else
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下代码显示进度对话框。
要取消对话框,您应该使用
dialog.cancel()
。取消对话框后,可以显示Toast
像这样改变你的代码
You can show progress dialog using following code
For cancelling the dialog, you should use
dialog.cancel()
. After cancelling dialog, you can displayToast
Change your code like this