Looking at alternative computer software solutions for a variety of reasons. This includes price, computer security, virus prevention and reliability.
Here are my notes and great that if it helps you, otherwise please understand what you are doing and not follow blindly.
All works expressed are my own and does not necessarily express the products or organisations mentioned here.

Wednesday, October 4, 2017

Android AlertDialog

How to display a delete confirmation box?

A simple method is to use AlertDialog that quickly provides the "CANCEL" and "OK" along with your custom confirmation message.

An example within a Fragment class where a user click's the Delete button which calls the deleteConfirmation( ) function with the title or name of item to be delete.

Note 1:
The Dialog class is the base class to AlertDialog that makes the user take an action before returning back to the Fragment or Activity. This is known as a Modal Event. Other example of Dialog class are DatePickerDialog and TimePickerDialog.

If used for Android API 25 and onward, the import statement is

import android.app.AlertDialog;

for API 11 to below API 25 use

import android.support.v7.app.AlertDialog;

Note 2:
There are 3 type of buttons that can be added (in the example above, only 2 are added) to an AlertDialog. Only one of each type can be added using the following methods;

Note 3:
There are several ways to pass message or status to the Activity or Fragment that created/launched the AlertDialog. In the example above, a static variable is declared in the MainActivity and values are changed base on button clicked.

In MainActivity.java

public static boolean confirmDelete=false;

Note 4:
To further customise the AlertDialog look, a resource file (XML) can be created and assigned with the method