Posted By

rso on 01/09/11


Tagged

android


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

D4RKCODE


Show MessageBox and Toast


 / Published in: Java
 

Code Snippet of showing dialog and toast in Android application.

  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  

You need to login to post a comment.