Created
February 1, 2017 13:13
-
-
Save alfianyusufabdullah/5d45bef7f93ae9c73bfb8f603a280401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.jonesrandom.tutorialalertdialog; | |
| 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 { | |
| /// 3 VARIABEL BUTTON | |
| Button alertDialog1; | |
| Button alertDialog2; | |
| Button alertDialog3; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| /// INISIALISASI VARIABEL BUTTON DENGAN VIEW | |
| alertDialog1 = (Button) findViewById(R.id.alertDialog_1); | |
| alertDialog2 = (Button) findViewById(R.id.alertDialog_2); | |
| alertDialog3 = (Button) findViewById(R.id.alertDialog_3); | |
| /// MENAMBAH LISTENER DI SETIAP BUTTON | |
| alertDialog1.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| /// MEMANGGIL ALERTDIALOG DENGAN 1 BUTTON | |
| AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); | |
| builder.setTitle("Ini AlertDialog Title"); | |
| builder.setMessage("Ini Pesan dari AlertDialog"); | |
| ///MENAMBAH BUTTON POSITIVE PADA BUILDER | |
| builder.setPositiveButton("OKE", new DialogInterface.OnClickListener() { | |
| @Override | |
| public void onClick(DialogInterface dialogInterface, int i) { | |
| Toast.makeText(MainActivity.this, "AlertDialog Positive Button Di klik", Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| AlertDialog dialog = builder.create(); | |
| dialog.show(); | |
| } | |
| }); | |
| alertDialog2.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| /// MEMANGGIL ALERTDIALOG DENGAN 2 BUTTON | |
| AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); | |
| builder.setTitle("Ini AlertDialog Title"); | |
| builder.setMessage("Ini Pesan dari AlertDialog"); | |
| ///MENAMBAH BUTTON POSITIVE PADA BUILDER | |
| builder.setPositiveButton("OKE", new DialogInterface.OnClickListener() { | |
| @Override | |
| public void onClick(DialogInterface dialogInterface, int i) { | |
| Toast.makeText(MainActivity.this, "AlertDialog Positive Button Di klik", Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| //MENAMBAH BUTTON NEGATIVE PADA BUILDER | |
| builder.setNegativeButton("BATAL", new DialogInterface.OnClickListener() { | |
| @Override | |
| public void onClick(DialogInterface dialogInterface, int i) { | |
| Toast.makeText(MainActivity.this, "AlertDialog Negative Button Di klik", Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| AlertDialog dialog = builder.create(); | |
| dialog.show(); | |
| } | |
| }); | |
| alertDialog3.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| /// MEMANGGIL ALERTDIALOG DENGAN 3 BUTTON | |
| AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); | |
| builder.setTitle("Ini AlertDialog Title"); | |
| builder.setMessage("Ini Pesan dari AlertDialog"); | |
| ///MENAMBAH BUTTON POSITIVE PADA BUILDER | |
| builder.setPositiveButton("SIMPAN", new DialogInterface.OnClickListener() { | |
| @Override | |
| public void onClick(DialogInterface dialogInterface, int i) { | |
| Toast.makeText(MainActivity.this, "AlertDialog Positive Button Di klik", Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| //MENAMBAH BUTTON NEGATIVE PADA BUILDER | |
| builder.setNegativeButton("HAPUS", new DialogInterface.OnClickListener() { | |
| @Override | |
| public void onClick(DialogInterface dialogInterface, int i) { | |
| Toast.makeText(MainActivity.this, "AlertDialog Negative Button Di klik", Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| //MENAMBAH BUTTON NEUTRAL PADA BUILDER | |
| builder.setNeutralButton("BATAL", new DialogInterface.OnClickListener() { | |
| @Override | |
| public void onClick(DialogInterface dialogInterface, int i) { | |
| Toast.makeText(MainActivity.this, "AlertDialog Neutral Button Di klik", Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| AlertDialog dialog = builder.create(); | |
| dialog.show(); | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment