Return to Snippet

Revision: 38891
at January 9, 2011 15:49 by rso


Updated Code
/**
 * Show message by alert
 * @param message
 * @param c current context
 */
private void _showAlert(final String message, final Context c) {
	Builder builder = new AlertDialog.Builder(c);
	builder.setMessage(message);
	builder.setPositiveButton(android.R.string.ok,
		new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
					// do nothing
				}
			});
	AlertDialog dialog = builder.create();
	dialog.show();
}


/**
 * Show context on UiThread
 * @param message
 * @param current context
 */
private void showToast(final String msg, final Context c) {
	Runnable showToastTask = new Runnable() {
		public void run() {
			Toast.makeText(c, msg, Toast.LENGTH_SHORT).show();
		}
	};
	runOnUiThread(showToastTask);
}

Revision: 38890
at January 9, 2011 15:47 by rso


Initial Code
/**
 * Show message by alert
 * @param message
 * @param c current context
 */
private void _showAlert(final String message, final Context c) {
	Builder builder = new AlertDialog.Builder(c);
	builder.setMessage(message);
	builder.setPositiveButton(android.R.string.ok,
		new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
					// do nothing
				}
			});
	AlertDialog dialog = builder.create();
	dialog.show();
}


/**
 * Show context on UiThread
 * @param message
 * @param current context
 */
private void showToast(final String msg, final Context c) {
	final Context ctx = c;
	Runnable dumpTask = new Runnable() {
		public void run() {
			Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show();
		}
	};
	runOnUiThread(dumpTask);
}

Initial URL

                                

Initial Description
Code Snippet of showing dialog and toast in Android application.

Initial Title
Show MessageBox and Toast

Initial Tags
android

Initial Language
Java