gui
-
(Android) Simple confirm dialog
[java] private void confirmDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder .setMessage("Are you sure?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // Yes-code } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog,int id) { dialog.cancel(); } }) .show(); } [/java]
-
(Android) Custom view orientation change – restore state.
Here’s one pretty simple way to get your custom view to restore its current state after an orientation change: You can of course put any values in there, for example if you need to restore fields. (quickly plotted code. Haven’t run it, but it should work) [java] @Override protected Parcelable onSaveInstanceState() { Bundle bundle =…
-
(Android) Convert Density-independent Pixels to Pixels (dp 2 px)
A simple function to convert dp into pixels. Use when you have to pass pixels to a method and want to keep everything to scale. [java] private int dp2px(int dp) { float scale = getResources().getDisplayMetrics().density; int pixels = (int) (dp * scale + 0.5f); return pixels; } [/java] From Android Developer Center : pxPixels –…
-
(C#) Confirmation when closing a form
Add an event handler for Form Closing and use this code. This is a really simple solution. [c language=”#”] private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Are you sure?", "Close application", MessageBoxButtons.YesNo) == DialogResult.Yes) e.Cancel = false; else e.Cancel = true; } [/c]
-
(C#) Scroll to bottom of a textbox
Short snippet: [c language=”#”] textBox.SelectionStart = textBox.TextLength; textBox.ScrollToCaret(); [/c]