angryegg

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  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("这是一个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 阅读(273) 评论(0)  编辑  收藏 所属分类: Android