Advertisement
taufiqhidayah97

toastactivity

Jul 28th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.92 KB | None | 0 0
  1. package com.example.taufiqhidayah.androidlayout;
  2.  
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.os.Build;
  6. import android.support.v7.app.AlertDialog;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.Toast;
  12.  
  13. public class toastactivity extends AppCompatActivity {
  14.     Context context = this;
  15.     Button btntoast, btnalert;
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_toastactivity);
  21.         btntoast = (Button) findViewById(R.id.btntoast);
  22.         btntoast.setOnClickListener(new View.OnClickListener() {
  23.             @Override
  24.             public void onClick(View v) {
  25.                 AlertDialog.Builder builder = new AlertDialog.Builder(context);
  26.                 builder.setTitle("Peringatan !");
  27.                 builder.setMessage("Anda Yakin Ingin Keluar ?");
  28.                 builder.setPositiveButton("Anda Keluar", new DialogInterface.OnClickListener() {
  29.                     @Override
  30.                     public void onClick(DialogInterface dialogInterface, int which) {
  31.                         Toast.makeText(toastactivity.this, "Yes", Toast.LENGTH_SHORT).show();
  32.                         toastactivity.this.finish();
  33.                     }
  34.                 });
  35.  
  36.                 builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
  37.                     @Override
  38.                     public void onClick(DialogInterface dialogInterface, int which) {
  39.                         Toast.makeText(getApplication(), "No", Toast.LENGTH_SHORT).show();
  40.                     }
  41.                 });
  42.                 builder.setNeutralButton("Yes", new DialogInterface.OnClickListener() {
  43.                     @Override
  44.                     public void onClick(DialogInterface dialogInterface, int which) {
  45.                         Toast.makeText(getApplication(), "Keluar", Toast.LENGTH_SHORT).show();
  46.                     }
  47.                 });
  48.                 builder.show();
  49.             }
  50.         });
  51.         btnalert = (Button) findViewById(R.id.btnalert);
  52.         btnalert.setOnClickListener(new View.OnClickListener() {
  53.             @Override
  54.             public void onClick(View view) {
  55.                 AlertDialog.Builder builder = new AlertDialog.Builder(context);
  56.                 builder.setTitle("Hai");
  57.                 builder.setMessage("Juga");
  58.                 builder.setPositiveButton("Baik", new DialogInterface.OnClickListener() {
  59.                     @Override
  60.                     public void onClick(DialogInterface dialogInterface, int i) {
  61.                         Toast.makeText(getApplication(), "Keluar", Toast.LENGTH_SHORT).show();
  62.                     }
  63.                 });
  64.                 builder.show();
  65.             }
  66.         });
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement