angryegg

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            0 隨筆 :: 5 文章 :: 0 評論 :: 0 Trackbacks

           

           1<?xml version="1.0" encoding="utf-8"?>
           2<LinearLayout
           3    xmlns:android="http://schemas.android.com/apk/res/android"
           4    android:orientation="vertical"
           5    android:layout_width="fill_parent"
           6    android:layout_height="fill_parent">
           7    <TextView
           8        android:layout_width="fill_parent"
           9        android:layout_height="wrap_content"
          10        android:text="@string/hello" />
          11    <Button
          12        android:id="@+id/button1"
          13        android:layout_width="fill_parent"
          14        android:layout_height="wrap_content" 
          15        android:text="單擊顯示彈出窗口"/>
          16</LinearLayout>
          17

           

           1public class BeginAndroidActivity extends Activity {
           2   private String tag = "Events";
           3 private CharSequence[] items = {"Google","Apple","HTC"};
           4   private boolean[] itemsChecked = new boolean[items.length];
           5  
           6  @Override
           7    public void onCreate(Bundle savedInstanceState) {
           8        super.onCreate(savedInstanceState);
           9        setContentView(R.layout.main);
          10        Log.d(tag, "In the onCreate() event");
          11        Button button = (Button) findViewById(R.id.button1);
          12        button.setOnClickListener(new View.OnClickListener() {
          13            public void onClick(View v) {
          14                showDialog(0);
          15            }

          16        }
          );
          17    }

          18}

          19

           

           1    @Override
           2    protected Dialog onCreateDialog(int id, Bundle args) {
           3        switch (id) {
           4        case 0:
           5            return new AlertDialog.Builder(this)
           6                .setIcon(R.drawable.icon)
           7                .setTitle("這是一個(gè)Dialog")
           8                .setPositiveButton("OK"new DialogInterface.OnClickListener() {
           9                    public void onClick(DialogInterface dialog, int which) {
          10                        Toast.makeText(getBaseContext(), "OK Clicked!", Toast.LENGTH_SHORT).show();
          11                    }

          12                }
          )
          13                .setNegativeButton("Cancel"new DialogInterface.OnClickListener() {
          14                    public void onClick(DialogInterface dialog, int which) {
          15                        Toast.makeText(getBaseContext(), "Cancel Clicked!", Toast.LENGTH_SHORT).show();
          16                    }

          17                }
          )
          18                .setMultiChoiceItems(items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() {
          19                    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
          20                        Toast.makeText(getBaseContext(), items[which] + (isChecked ? " checked!" :" unChecked!"), Toast.LENGTH_SHORT).show();
          21                    }

          22                }
          )
          23                .create();
          24        }

          25        return null;
          26
          27}


           

           

          posted on 2011-07-31 15:36 angryegg 閱讀(271) 評論(0)  編輯  收藏 所屬分類: Android
          主站蜘蛛池模板: 江都市| 商都县| 镇赉县| 武安市| 宿迁市| 蓬莱市| 大名县| 永和县| 萍乡市| 洪湖市| 墨竹工卡县| 新建县| 宾阳县| 江津市| 垫江县| 无锡市| 湖州市| 梁山县| 杭州市| 台北市| 个旧市| 桂阳县| 安图县| 澄城县| 团风县| 灵寿县| 商水县| 大同县| 孟州市| 昭苏县| 如皋市| 尚志市| 德兴市| 宁乡县| 彭州市| 从化市| 湘潭市| 江山市| 浙江省| 清远市| 惠州市|