Android—AlertDialog提示信息
来源:互联网 发布:电力软件 编辑:程序博客网 时间:2024/05/16 14:30
一、
content_main.xml
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮" android:id="@+id/button1" android:onClick="DialogClick1" android:layout_alignParentTop="true" android:layout_alignParentStart="true" android:layout_alignParentEnd="true" />
MainActivity.java
public void DialogClick1(View v) { //创建一个提示对话框的创造者 AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setTitle("提示"); builder.setMessage("您有女朋友吗"); builder.setIcon(R.mipmap.ic_launcher); //正面按钮 builder.setPositiveButton("有", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "你可以走了", Toast.LENGTH_SHORT).show(); } }); //反面按钮 builder.setNegativeButton("没有", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "欢迎加入单身俱乐部", Toast.LENGTH_SHORT).show(); } }); //中立按钮 builder.setNeutralButton("隐藏", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,"有没有并不重要",Toast.LENGTH_SHORT).show(); } }); //AlertDialog dialog= builder.create(); //dialog.show(); builder.show(); }
运行结果:
二、
content_main.xml
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="列表" android:id="@+id/button2" android:onClick="DialogClick2" android:layout_below="@+id/button1" android:layout_alignParentStart="true" android:layout_alignParentEnd="true" />
MainActivity.java
public void DialogClick2(View v){ AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setTitle("请选择一个平台:"); final String[]items={"Android","IOS","Window Phone"}; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,items[which],Toast.LENGTH_SHORT).show(); } }); builder.show(); }
运行结果:
三、
content_main.xml
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="多选" android:id="@+id/button3" android:onClick="DialogClick3" android:layout_below="@+id/button2" android:layout_alignParentStart="true" android:layout_alignParentEnd="true" />MainActivity.java
public void DialogClick3(View v){ AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setTitle("请选择一个平台:"); final ArrayList<String>List=new ArrayList<String>(); final String[]items={"Android","IOS","Window Phone"}; builder.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if(isChecked) { List.add(items[which]); } else { List.remove(items[which]); } } }); //正面按钮 builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, List.toString(), Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }); //反面按钮 builder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { List.clear(); dialog.dismiss(); } }); builder.show(); }
运行结果:
0 0
- Android—AlertDialog提示信息
- Android控件之AlertDialog-信息提示框
- Android之置顶提示警告信息的控件AlertDialog
- android 提示对话框显示 AlertDialog
- Android AlertDialog 提示设置网络
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- Android使用设置AlertDialog(退出提示框)
- Android使用自定义AlertDialog(退出提示框)
- A*B Problem II
- leetcode-python 第五周
- 浏览器打开应用指定的界面
- 单例
- STL map的用法介绍!
- Android—AlertDialog提示信息
- 解决异步获取user session的方法
- SharedPreferences判断是否第一次进入程序
- hdu 4438 Hunters【数学水题】
- Gson选择性排除序列化字段
- Android Service基础之Bound Services
- Linux命令速查手册
- 自动化测试用例编写守则
- Hbase java创建表时,调试一直卡住