Show MessageBox and Toast


/ Published in: Java
Save to your folder(s)

Code Snippet of showing dialog and toast in Android application.


Copy this code and paste it in your HTML
  1. /**
  2.  * Show message by alert
  3.  * @param message
  4.  * @param c current context
  5.  */
  6. private void _showAlert(final String message, final Context c) {
  7. Builder builder = new AlertDialog.Builder(c);
  8. builder.setMessage(message);
  9. builder.setPositiveButton(android.R.string.ok,
  10. new DialogInterface.OnClickListener() {
  11. public void onClick(DialogInterface dialog, int which) {
  12. // do nothing
  13. }
  14. });
  15. AlertDialog dialog = builder.create();
  16. dialog.show();
  17. }
  18.  
  19.  
  20. /**
  21.  * Show context on UiThread
  22.  * @param message
  23.  * @param current context
  24.  */
  25. private void showToast(final String msg, final Context c) {
  26. Runnable showToastTask = new Runnable() {
  27. public void run() {
  28. Toast.makeText(c, msg, Toast.LENGTH_SHORT).show();
  29. }
  30. };
  31. runOnUiThread(showToastTask);
  32. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.