在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择。这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式。下面我们简单模拟一个选花魁的简单普通选项(单选)对话框,如下图:

Layout界面代码:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="普通选项"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="show2"
android:id="@+id/button2" />
</LinearLayout>

Java功能实现代码:

 public class AlertDialogDemo extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alertdialog);
}
public void show2(View v){
//实例化建造者
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//设置警告对话框标题
builder.setTitle("选花魁喽");
//定义警告框选择窗体的内容(这里用String数组)
final String[] beautifulGirls = {"芙蓉姐姐","凤姐","范爷","我自己"};
//将数组内的元素设置到dialog的每个item中,并做事件处理(这里用土司)
builder.setItems(beautifulGirls, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(AlertDialogDemo.this,beautifulGirls[which]+"被选中啦",Toast.LENGTH_SHORT).show();
}
});
//显示对话框
builder.show();
}
}

Android中的AlertDialog使用示例二(普通选项对话框)的更多相关文章

  1. Android中的AlertDialog使用示例一(警告对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  2. Android中的AlertDialog使用示例五(自定义对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  3. Android中的AlertDialog使用示例三(单向选择确定对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  4. Android中使用AlertDialog实现几种不同的对话框

    场景 app中常见的对话框. 简单的带确定取消按钮的对话框 带列表的对话框 带单项选择的对话框 带多项选择的对话框 注: 博客: https://blog.csdn.net/badao_liumang ...

  5. Android中的AlertDialog使用示例四(多项选择确定对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  6. Android 中的AlertDialog使用自定义布局

    Android使用指定的View开发弹窗功能 Android开发中进程会使用到我们的AlertDialog,但是比较可惜的是我们的Android原生的AlertDialog的效果又比较的简陋,这个时候 ...

  7. Android中ProgressDialog的简单示例

    网上一般对进度条的示例都是如何显示,没有在任务结束如何关闭的文章,参考其他文章经过试验之后把整套进度条显示的简单示例如下: 建立android工程等工作都略去,Google一下就可以了. 下面来介绍主 ...

  8. 详细解读Android中的搜索框(二)—— Search Dialog

    Search Dialog是提供搜索的控件之一,还有一个是上次小例子给出的searchView,关于SearchView的东西后面会说到.本次先从Search Dialog说起,让大家慢慢理解andr ...

  9. Android中的数据存储(二):文件存储 2017-05-25 08:16 35人阅读 评论(0) 收藏

    文件存储 这是本人(菜鸟)学习android数据存储时接触的有关文件存储的知识以及本人自己写的简单地demo,为初学者学习和使用文件存储提供一些帮助.. 如果有需要查看SharedPreference ...

随机推荐

  1. OpenCascade Primitives BRep-Cone

    OpenCascade Primitives BRep-Cone eryar@163.com Abstract. BRep is short for Boundary Representation. ...

  2. MySQL分区表的管理~2

    一.维护分区 对于表的维护,我们一般有如下几种方式: CHECK TABLE, OPTIMIZE TABLE, ANALYZE TABLE和REPAIR TABLE. 而这几种方式,对于分区同样适用. ...

  3. EF CodeFirst EntityTypeConfiguration 自关联映射配置

    实体示例代码: public class Message { public Message() { } public int ID { get; private set; } public strin ...

  4. Lua 学习笔记(七)编译、执行外部代码块

    Lua称为解释型语言的原因:Lua允许在运行源代码之前,先将源代码预编译为一种中间形式.区别解释型语言的主要特征是在于编译器是否是语言运行时库的一部分,即有能力执行动态生成的代码.因为Lua中有dof ...

  5. geotrellis使用(六)Scala并发(并行)编程

    本文主要讲解Scala的并发(并行)编程,那么为什么题目概称geotrellis使用(六)呢,主要因为本系列讲解如何使用Geotrellis,具体前几篇博文已经介绍过了.我觉得干任何一件事情基础很重要 ...

  6. 计时器StopWatch示例

    计时器 StopWatch stwatch = new StopWatch(getClass().getSimpleName()); try{ stwatch.start(joinPoint.getS ...

  7. ANNOTATION PROCESSING 101 by Hannes Dorfmann — 10 Jan 2015

    原文地址:http://hannesdorfmann.com/annotation-processing/annotationprocessing101 In this blog entry I wo ...

  8. Ueditor 增加模板

    简介: Ueditor 是百度出的开源富文本编辑器,非常符合国人习惯!模板功能很好用. 官网:http://ueditor.baidu.com/website/ 定义自己的模板: 先用Ueditor编 ...

  9. activity结束之后刷新之前的activity的内容

    点击添加按钮之后-----弹出一个新的activity--------在新的activity将数据输入保存之后,关闭当前的activity回到之前的activity刷新内容 实现:使用onActivi ...

  10. Qt自适应大小显示图片,添加菜单

    由于后面的图像处理需要UI,OpenCV自带也不怎么会,MFC实在懒得学的.听同学说Qt不错,就用Qt做UI了. 本文主要介绍三个内容:在Qt Creator中使用OpenCV2.Qt中自适应显示图片 ...