Menampilkan Simple Message Box di Android (tutorial)

Di android terdapat 2 cara untuk menampilkan pesan melalui message box, yaitu terdiri dari:

  1. Toast - menampilkan balloon pop-up kecil yang biasanya berisi sedikit informasi yang hilang dengan sendirinya setelah beberapa detik.
  2. AlertDialog - menampilkan berupa window seperti alert beserta tombolnya.

Berikut ini contoh sederhana dalam menerapkannya :

Toast:

Toast.makeText(this, "Hello World", Toast.LENGTH_SHORT).show();

AlertDialog:

AlertDialog ad = new AlertDialog.Builder(this).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("Hello World");
ad.setButton("OK", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
    }
});
ad.show();

Done!





Calendar

May 2012
M T W T F S S
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 1 2 3

Category Key

  • General

© alfach.com 2012 - Feel free to leave your comment