angryegg
BlogJava
::
首页
::
新随笔
::
联系
::
聚合
::
管理
::
0 随笔 :: 5 文章 :: 0 评论 :: 0 Trackbacks
<
2025年7月
>
日
一
二
三
四
五
六
29
30
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
4
5
6
7
8
9
留言簿
给我留言
查看公开留言
查看私人留言
文章分类
Android(5)
(rss)
文章档案
2011年7月 (5)
搜索
最新评论
乐学Android之05:显示Dialog Window
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
1
public
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
阅读(272)
评论(0)
编辑
收藏
所属分类:
Android
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
相关文章:
乐学Android之04:隐藏标题栏
乐学Android之05:显示Dialog Window
乐学Android之03:Activity样式
乐学Android之02:Activity生命周期
乐学Android之01:Android开发环境搭建全程演示
Powered by:
BlogJava
Copyright © angryegg