How to check if a value is a double value in Android (Java)

To check if a value is a double value in Android you can use the snippet below.

Samples

Java (Android) Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to refresh the current Android Fragment

To refresh the current Android Fragment you can use the snippet below. The code must be placed inside the Fragment that needs to be updated. The snippet will call the onCreateView Method of the Fragment.

Samples

Sample Java

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to show software keyboard when focusing textedit in Android

To show software keyboard when focusing textedit in Android you can use the snippet below.

Sample Java

myTextEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean focus) {
        if (focus) {
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
});

Please rate this snippet

How to create an alert dialog in Android

To create an alert dialog in Android you can use the following snippet.

Sample Java

new AlertDialog.Builder(this)
    .setTitle("Delete items")
    .setMessage("Are you sure you want to delete this items?")
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // YES
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // NO
        }
     })
    .setIcon(android.R.drawable.ic_dialog_alert)
     .show();

Please rate this snippet

How to detect a screen orientation change in Javascript

To detect a screen orientation change in Javascript you can use the following snippet.

Sample Javascript

window.addEventListener("orientationchange", function() {
	//0 = potrait
	//90 or -90 = landscape left or landscape right
}, false);

some devices do not fire the orientationchange event, try the resize event instead.

Sample Javascript

window.addEventListener("resize", function() {
	// check screen size (inner and outer!)	
}, false);

Please rate this snippet