Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

alertdialog show in android

  AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.do_you_really_want_to_signout));
        builder.setTitle(getResources().getString(R.string.sign_out));
        builder.setCancelable(false);
        builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(AccountActivity.this, R.string.log_out_success,
                        Toast.LENGTH_LONG).show();
               
            }
        });

        AlertDialog alert = builder.create();
        alert.show();
Comment

android studio alert dialog box

package org.geeksforgeeks.navedmalik.alertdialog;
  
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
  
public class MainActivity extends AppCompatActivity {
  
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
  
    // Declare the onBackPressed method
    // when the back button is pressed
    // this method will call
    @Override
    public void onBackPressed()
    {
  
        // Create the object of
        // AlertDialog Builder class
        AlertDialog.Builder builder
            = new AlertDialog
                  .Builder(MainActivity.this);
  
        // Set the message show for the Alert time
        builder.setMessage("Do you want to exit ?");
  
        // Set Alert Title
        builder.setTitle("Alert !");
  
        // Set Cancelable false
        // for when the user clicks on the outside
        // the Dialog Box then it will remain show
        builder.setCancelable(false);
  
        // Set the positive button with yes name
        // OnClickListener method is use of
        // DialogInterface interface.
  
        builder
            .setPositiveButton(
                "Yes",
                new DialogInterface
                    .OnClickListener() {
  
                        @Override
                        public void onClick(DialogInterface dialog,
                                            int which)
                        {
  
                            // When the user click yes button
                            // then app will close
                            finish();
                        }
                    });
  
        // Set the Negative button with No name
        // OnClickListener method is use
        // of DialogInterface interface.
        builder
            .setNegativeButton(
                "No",
                new DialogInterface
                    .OnClickListener() {
  
                        @Override
                        public void onClick(DialogInterface dialog,
                                            int which)
                        {
  
                            // If user click no
                            // then dialog box is canceled.
                            dialog.cancel();
                        }
                    });
  
        // Create the Alert dialog
        AlertDialog alertDialog = builder.create();
  
        // Show the Alert Dialog box
        alertDialog.show();
    }
}
Comment

how to create alert dialog in android studio

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.do_you_really_want_to_signout));
        builder.setTitle(getResources().getString(R.string.sign_out));
        builder.setCancelable(false);
        builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(AccountActivity.this, R.string.log_out_success,
                        Toast.LENGTH_LONG).show();
               
            }
        });

        AlertDialog alert = builder.create();
        alert.show();
Comment

menu alert dialog in android

//create an instance of AlertDialog.Builder
AlertDialog.Builder builder = new AlertDialog.Builder(this);

//get string array (languages)
final String[] language = getResources().getStringArray(R.array.languages);

builder.setTitle(getText(R.string.select_language_title))

        //Set language(list of languages) to be displayed in the dialog as the content.
        .setItems(language, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int indexPosition) {

                // The 'indexPosition' argument contains the index position
                // of the selected item
                String selectedItem = Arrays.asList(language).get(indexPosition);
                Toast.makeText(getApplicationContext(), "Selected Language: " + selectedItem, Toast.LENGTH_LONG).show();

            }
        });

//create an AlertDialog
AlertDialog alertDialog = builder.create();

//display the dialog on screen
alertDialog.show();
Comment

PREVIOUS NEXT
Code Example
Java :: register watch service java 
Java :: first character string number java 
Java :: java remove map 
Java :: java read integer from text file into array scanner 
Java :: how to multiply bigdecimals 
Java :: labelled break statement in Java 
Java :: declare java class 
Java :: converting char array to string 
Java :: How do you count characters in a string array in Java? 
Java :: java lb to kg 
Java :: android setTextColor not working 
Java :: combine two array in java 
Java :: java explicit array declaration 
Java :: set toolbar background color android 
Java :: java list get first element 
Java :: java actionevent 
Java :: how to set context path in spring boot 
Java :: zweidimensionales array ausgeben java 
Java :: android access main toolbar in fragment 
Java :: java input - how to read a string 
Java :: How to efficiently find the start node of a loop within a singly linked list, in Java? 
Java :: sort 2d array based on one column java 
Java :: wait method in java 
Java :: how to convert string to int in java 
Java :: priority queue java comparator 
Java :: 2 decimal places print format JAVA 
Java :: java creating a stack 
Java :: get role assigned to a user inside spring controller 
Java :: Missing artifact com.sun.jersey:jersey-servlet:jar:1.20-SNAPSHOT 
Java :: java generics 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =