Android Studio Tutorial: Alert Dialog

This tutorial will show how to create an Alert Dialog in Android Studio. An Alert Dialog is a pop-up message that a user can either interact with to pass data or can just display a simple message. For this tutorial it will just display a message to the apps users.

This app will consist of a button the user will press to display the Alert Dialog Box.


Here is the layout file of the app. It includes the button that must be clicked to display the Alert Message.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=""

        android:text="Click Me!"
        app:layout_constraintVertical_bias="0.0" />

This portion of code is the actual function of the app.

public class MainActivity extends AppCompatActivity {

    Button mButton;

    protected void onCreate(Bundle savedInstanceState) {

        mButton = findViewById(;

        mButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

/// This is where the Alert Dialog is being created
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();

/// Here the Tile is being set
        alertDialog.setTitle("Alert Dialog Example.");

/// Here the message content is being set 
        alertDialog.setMessage("This is an alert dialog. 
        Project source code in description.");              
  alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {

That’s it!

Android Studio Loading Animation Between Activities

Progress Dialog is dialog showing a progress indicator and an optional text message or view. The methods of Progress Dialog being used in this tutorial are: ProgressDialog.setTitle() – Used to set title of dialog box ProgressDialog.setMessage() – Used to set dialog message being displayed ProgressDialog.setProgressStyle() – Choose the style of indicator ProgressDialog.dismiss() – Dismiss the…

Android Studio Tutorial SeekBar

SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch thumb and drag left or right to set the current progress level or various other task. In this example, the seekbar will be used to display a percentage. As the user moves the SeekBar left to right the percentage value…

Python Ethereum Block Chain Interaction with Web3

This tutorial will show how to interact with the Ethereum blockchain using Python. To start, the Python library Web3 will need to be installed. The Web3 library allows you to interact with a local or remote Ethereum node, using a HTTP or IPC connection. Using Web3 you will be able to create smart contracts on…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s