Belajardengan.com merupakan domain blog lama dari delajardengan.blogspot.com. Mohon kritik dan sarannya untuk perkembangan blog ini.
email: blog.tkx.pnp@gmail.com

coba Belajar Adroid (9)

♠ Posted by Unknown in at 10:46 PM

file *.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Contoh penggunaan dari AlertDialog JARC-SEAMOLEC"
    />
</LinearLayout>


Tes2sanActivity.java 
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

public class Tes2sanActivity extends Activity {
    /** Called when the activity is first created. */
      Button btn;
      @Override
    public void onCreate(Bundle savedInstanceState) {
           
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final CharSequence[] warna = {"Sirah", "Kuniang", "Ijau" , "Biru"};

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Pilih warna kesukaan mu ");
        builder.setItems(warna, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                Toast.makeText(getApplicationContext(), warna[item], Toast.LENGTH_SHORT).show();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
      }    
}

Hasilnya:



0 komentar:

Post a Comment