SHARE
TWEET

Untitled

a guest Feb 17th, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.myapplication;
  2.  
  3. import androidx.appcompat.app.AlertDialog;
  4. import androidx.appcompat.app.AppCompatActivity;
  5.  
  6. import android.content.DialogInterface;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14.  
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.activity_main);
  19.  
  20.         Button btnToast = (Button) findViewById(R.id.btnToast);
  21.         btnToast.setOnClickListener(new View.OnClickListener() {
  22.             @Override
  23.             public void onClick(View v) {
  24.                 EditText txtNama = (EditText) findViewById(R.id.txtNama);
  25.                 String nama = txtNama.getText().toString();
  26.  
  27.                 Toast.makeText(getApplicationContext(), "Halo" + nama + "...", Toast.LENGTH_SHORT).show();
  28.             }
  29.         });
  30.  
  31.         Button btnDialog = (Button) findViewById(R.id.btnDialog);
  32.         btnDialog.setOnClickListener(new View.OnClickListener() {
  33.             @Override
  34.             public void onClick(View view) {
  35.                 EditText txtNama = (EditText) findViewById(R.id.txtNama);
  36.                 String nama = txtNama.getText().toString();
  37.  
  38.                 AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
  39.                 dialog.setTitle("Sapaan");
  40.                 dialog.setMessage("Halo" + nama + "...");
  41.                 dialog.setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
  42.                     @Override
  43.                     public void onClick(DialogInterface dialog, int which) {
  44.  
  45.                     }
  46.                 });
  47.                 dialog.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
  48.                     @Override
  49.                     public void onClick(DialogInterface dialog, int which) {
  50.                     }
  51.  
  52.                 });
  53.                 dialog.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
  54.                     @Override
  55.                     public void onClick(DialogInterface dialogInterface, int which) {
  56.  
  57.                     }
  58.                 });
  59.                 dialog.show();
  60.             }
  61.         });
  62.     }
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top