免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1799 | 回复: 1
打印 上一主题 下一主题

在 Android 应用中使用警示框 Alerts [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-07 17:07 |只看该作者 |倒序浏览
  1. //declared as final to be able to reference it in inner class declartations of the handlers
  2.      final AlertDialog.Builder builder=new AlertDialog.Builder(this);
  3.      builder.setTitle("Alert Dialog");
  4.      builder.setMessage("This is the alert's body");
  5.      builder.setIcon(android.R.drawable.ic_dialog_alert);
  6.      
  7.      builder.setPositiveButton("OK", new OnClickListener() {
  8.    
  9.    @Override
  10.    public void onClick(DialogInterface dialog, int which) {
  11.     TextView txt=(TextView)findViewById(R.id.txt);
  12.     txt.setText("You clicked Ok");
  13.    }
  14.   });
  15.      
  16.      builder.setNegativeButton("Cancel", new OnClickListener() {
  17.    
  18.    @Override
  19.    public void onClick(DialogInterface dialog, int which) {
  20.     // TODO Auto-generated method stub
  21.     TextView txt=(TextView)findViewById(R.id.txt);
  22.     txt.setText("You clicked Cancel");
  23.    }
  24.   });
  25.      
  26.      builder.setNeutralButton("Do something", new OnClickListener() {
  27.    
  28.    @Override
  29.    public void onClick(DialogInterface dialog, int which) {
  30.     // TODO Auto-generated method stub
  31.     TextView txt=(TextView)findViewById(R.id.txt);
  32.     txt.setText("Neutral Button Clicked");
  33.     AlertDialog ad=builder.create();
  34.     ad.cancel();
  35.    }
  36.   });
  37.      
  38.      builder.setOnCancelListener(new OnCancelListener() {
  39.    
  40.    @Override
  41.    public void onCancel(DialogInterface dialog) {
  42.     // TODO Auto-generated method stub
  43.     TextView txt=(TextView)findViewById(R.id.txt);
  44.     txt.setText(txt.getText()+" the cancel listner invoked");
  45.    }
  46.   });
  47.      
  48.      
  49.      
  50.      builder.show();
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-04-11 13:19 |只看该作者
学习了,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP