Alert Dialog Builder

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private Button mybutton;
private AlertDialog.Builder dialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mybutton = findViewById(R.id.buttonLayout);

mybutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {


// Create dialog
// Criar o dialog
dialog = new AlertDialog.Builder(MainActivity.this);

// Dialog Title
// Titulo da dialog
dialog.setTitle("Title of dialog");

// Dialog Mesage
// Mensagem da dialog
dialog.setMessage("Dialog Message blá, blá, blá ?");

// Not possible to cancel
// Caixa obrigatoria não cancelável
dialog.setCancelable(false);

// Put ant icon in the dialog
// Colocar um icon na caixa de dialogo
dialog.setIcon(android.R.drawable.ic_dialog_info);

// Creat positive and negative answer
// Criar resposta positiva e negativa
dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "Yes pressed", Toast.LENGTH_LONG).show();
}
});
dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this, "No pressed", Toast.LENGTH_LONG).show();
}
});

// Mont dialog box
// Montar a dialog
dialog.create();
dialog.show();
}
});
}
}

Deixe uma resposta

O seu endereço de email não será publicado.