WarnaActivity.java
package app.warna.hw;
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 WarnaActivity 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 = {"Pink", "Biru", "Hijau" , "Merah"};
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();
}
}
main.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 by vhyemuuth"
/>
LinearLayout>
0 komentar:
Posting Komentar
Mohon tinggalkan komentar anda karena komentar anda adalah
Sumber Ilmu buat saya...terimakasih..!!!