![](/img/trans.png)
[英]Code to Show Toast message after dismiss the progress dialog in android?
[英]Android: Progress dialog and toast
任何人都可以幫助我如何放置一個進度對話框,該對話框加載5秒鍾並在之后顯示快速? 這是代碼:
btnSend.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String phoneNo = editTextRecipient.getText().toString();
String message = editTextNewMessage.getText().toString();
setResult(RESULT_OK);
saveState(phoneNo, message);
final Toast toast = Toast.makeText(getBaseContext(),
"Your message " + "\"" + message + "\"" + " is sent to " +"\""+ phoneNo+"\"",
Toast.LENGTH_SHORT);
toast.show();
Intent setIntent = new Intent(Edit_Message.this, Main.class);
startActivity(setIntent);
}
});
}
我想放一個5秒的進度對話框和一個提示消息已發送的提示。 誰能幫我?
請嘗試這個
showProgress ();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
dialog.cancel();
Intent i=new Intent(getApplicationContext(),Main.class);
startActivity(i);
finish();
}
}, 5000);
private ProgressDialog dialog;
public void showProgress () {
dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setMessage("Please wait");
dialog.show();
}
如果您確實需要使進度條保持5秒鍾,則使用“進度對話框”和“ Java線程” **“進度對話框**”,但是如果您需要使其動態化,則最好使用AsyncTask 。 根據您的描述,您需要在完成加載后引發Toast,然后可以在完成線程后或在asynctask
中asynctask
onPostExecute()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.