Last active
February 1, 2017 13:09
-
-
Save alfianyusufabdullah/3daa52d2a8182a6441dd78f665fc8d44 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) { | |
| /// KODE UNTUK MEMANGGIL ALERTDIALOG | |
| } | |
| }); | |
| alertDialog3.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| /// KODE UNTUK MEMANGGIL ALERTDIALOG | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment