AlertDialog使用实例
2011-08-31 12:32
148 查看
创建项目AlertDialogDemo如图
AlertDialogDemo.java文件代码如下:
viewsourceprint?
main.xml文件如下:
viewsourceprint?
viewsourceprint?
运行实例效果截图:
AlertDialogDemo.java文件代码如下:
01 | package zerone.AlertDialogDemo; |
02 |
03 | import
|
04 |
05 | public class AlertDialogDemo extends Activity{ |
06 | /**Calledwhentheactivityisfirstcreated.*/ |
07 | final int DIALOG_WELCOME= 1 ; |
08 | private Buttonbtn_alert; |
09 | @Override |
10 | public void onCreate(BundlesavedInstanceState){ |
11 | super .onCreate(savedInstanceState); |
12 | setContentView(R.layout.main); |
13 | btn_alert=(Button)findViewById(R.id.btn_dialog); |
14 | btn_alert.setOnClickListener( new View.OnClickListener(){ |
15 | @Override |
16 | public void onClick(Viewv){ |
17 | showDialog(DIALOG_WELCOME); //调用onCreateDialog |
18 | } |
19 | }); |
20 | } |
21 |
22 | @Override |
23 | protected DialogonCreateDialog( int id,Bundleargs){ |
24 | switch (id){ |
25 | case DIALOG_WELCOME: |
26 | return new AlertDialog.Builder(AlertDialogDemo. this ) |
27 | .setTitle( "欢迎" ).setMessage( "欢迎使用本程序" ) |
28 | .setIcon(android.R.drawable.ic_dialog_info) |
29 | .setPositiveButton( "确定" , new OnClickListener(){ |
30 | @Override |
31 | public void onClick(DialogInterfacedialog, int which){ |
32 | Toast.makeText(AlertDialogDemo. this , "点击\"确定\"按钮后" ,Toast.LENGTH_SHORT).show(); |
33 | } |
34 | }).create(); |
35 | default : |
36 | return null ; |
37 | } |
38 | } |
39 |
40 | } |
01 | <? xml version = "1.0" encoding = "utf-8" ?> |
02 | < LinearLayout xmlns:android = " |
03 | android:orientation = "vertical" |
04 | android:layout_width = "fill_parent" |
05 | android:layout_height = "fill_parent" |
06 | > |
07 | < TextView |
08 | android:layout_width = "fill_parent" |
09 | android:layout_height = "wrap_content" |
10 | android:text = "@string/app_title" |
11 | /> |
12 | < Button |
13 | android:id = "@+id/btn_dialog" |
14 | android:layout_width = "fill_parent" |
15 | android:layout_height = "wrap_content" |
16 | android:text = "弹出" /> |
17 | </ LinearLayout > |
1 |
相关文章推荐
- AlertDialog使用实例
- AlertDialog使用实例
- Android AlertDialog对话框的使用及实例(显示提示消息的对话框)
- android AlertDialog的简单使用实例
- 【Android】Android中AlertDialog对话框的使用实例
- 【Android】Android中AlertDialog对话框的使用实例
- 使用spring jdbc template简化jdbc数据库操作实例代码
- arraylist结合iterator使用实例
- 使用PHPExcel操作Excel用法实例分析
- Java wait() notify()方法使用实例讲解
- boost之线程池使用实例
- 【翻译自mos文章】rac数据库中,HC_<SID>.dat文件被其他Oracle_Home下的实例所使用。
- sys_refcursor的使用方法实例
- 页面静态化技术Freemarker技术的介绍及使用实例.
- 函数指针的使用c++代码实例及运行结果
- numpy使用fromstring创建矩阵的实例
- Zookeeper实例原生API--使用错误权限信息的ZooKeeper会话访问含权限信息的数据节点
- C#中的Linq Intersect与Except方法使用实例
- web.config 关于HttpHandlers 和HttpModules的使用实例【转】
- 〖Linux〗iptables使用实例