安卓——AlertDialog多样按钮
- 在xml 设计页面添加标签
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.administrator.app_style.MainActivity"
android:orientation="vertical"> <Button
android:id="@+id/b1"
android:text="click select!"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/b2"
android:text="click Dx!"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </LinearLayout>
2. //多选按钮
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String[] s={"h5","python","Java","c#","Php","Android"};
boolean []b={false,false,false,false,false,false};
new AlertDialog.Builder(MainActivity.this).setIcon(R.mipmap.ic_launcher)
.setTitle("问问你,你宣啥?")
.setPositiveButton("Ok",null)
.setMultiChoiceItems(s, b, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if(isChecked==true)
{
Toast.makeText(MainActivity.this,"你选了:"+s[which]+ " 这个语言,看来你很喜欢他啊!",Toast.LENGTH_SHORT).show();
}
if(isChecked==false)
{
Toast.makeText(MainActivity.this,"你取消了:"+s[which]+ " 这个语言,看来你移情别恋了啊!",Toast.LENGTH_SHORT).show();
}
}
}).show();
}
});
3 单选按钮
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String[] s={"h5","python","Java","c#","Php","Android"};
new AlertDialog.Builder(MainActivity.this).setIcon(R.mipmap.ic_launcher)
.setTitle("问问你,你宣啥?")
.setPositiveButton("Ok",null)
.setSingleChoiceItems(s,0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"你选了:"+s[which]+ " 这个语言,看来你很喜欢他啊!",Toast.LENGTH_SHORT).show();
}
}).show();
}
});
- 在xml 设计页面添加标签
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.administrator.app_style.MainActivity"
android:orientation="vertical"> <Button
android:id="@+id/b1"
android:text="click select!"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/b2"
android:text="click Dx!"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </LinearLayout>
2. //多选按钮
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String[] s={"h5","python","Java","c#","Php","Android"};
boolean []b={false,false,false,false,false,false};
new AlertDialog.Builder(MainActivity.this).setIcon(R.mipmap.ic_launcher)
.setTitle("问问你,你宣啥?")
.setPositiveButton("Ok",null)
.setMultiChoiceItems(s, b, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if(isChecked==true)
{
Toast.makeText(MainActivity.this,"你选了:"+s[which]+ " 这个语言,看来你很喜欢他啊!",Toast.LENGTH_SHORT).show();
}
if(isChecked==false)
{
Toast.makeText(MainActivity.this,"你取消了:"+s[which]+ " 这个语言,看来你移情别恋了啊!",Toast.LENGTH_SHORT).show();
}
}
}).show();
}
});
3 单选按钮
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String[] s={"h5","python","Java","c#","Php","Android"};
new AlertDialog.Builder(MainActivity.this).setIcon(R.mipmap.ic_launcher)
.setTitle("问问你,你宣啥?")
.setPositiveButton("Ok",null)
.setSingleChoiceItems(s,0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"你选了:"+s[which]+ " 这个语言,看来你很喜欢他啊!",Toast.LENGTH_SHORT).show();
}
}).show();
}
});
安卓——AlertDialog多样按钮的更多相关文章
- 微信公众号使用vue,安卓端点击按钮404,ios访问正常问题
情景:微信公众号使用vue开发的单页面,在安卓端点击按钮访问显示404,ios访问正常问题,能正常显示. 解决:将微信公众号菜单按钮设置的路径中把WWW去掉后,安卓.ios都能正常访问. 问题路径ww ...
- 于Unity3D调用安卓AlertDialog
例如,下面的示例代码演示 package com.sample.sampletest; import android.app.AlertDialog; import android.content.D ...
- [Android] 设置AlertDialog中按钮的可用(Enable)状态
弹出一个保存文件的对话框,要控制输入内容限制,同时内容为空时保存按钮不可用. 原文地址请保留http://www.cnblogs.com/rossoneri/p/4140184.html 直接上代码: ...
- 安卓AlertDialog四种对话框的最科学编写用法
首先我们上图: xml的代码如下,用于编写按钮: <?xml version="1.0" encoding="utf-8"?> <Linear ...
- 安卓多个按钮使用一个OnClickListener
安卓studio 3.1 版本编译通过 一个按钮id为bt1 一个按钮Id为bt2 mainactivity 代码入下 package com.example.vmpdump.firstapp; im ...
- 安卓AlertDialog的使用
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage("数 ...
- 安卓AlertDialog 的使用
引入空间 import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; fin ...
- 安卓ImageButton圆角按钮设置
首先图片要做成圆角的,使用美图秀秀,这个不多说. 之后使用设置了圆角的按钮,效果有缺陷,按钮会有灰色的边角. 类似这样: 去掉的方法是将layout的 android:src="@draw ...
- 在安卓手机下按钮会悬浮在键盘上,怎么解决vue.js
data里面 screenHeight: window.innerHeight mounted里面 mounted () { var that = this var u = navigator.use ...
随机推荐
- ps/kill/pkill简单应用
ps http://www.cnblogs.com/wangkangluo1/archive/2011/09/23/2185938.html 参数: 1)ps a 显示现行终端机下的所有程序,包括其他 ...
- 1、Python中的正则表达式(0601)
回顾: 1.文件对象: open('file','mode','bufsize') read,readline,readlines,write,writelines,flush,seek,tell 2 ...
- 使用mod_deflate模块压缩页面优化传输速度
在HTTPD主配置文件中添加如下,并确保deflate模块是启用的 #vim /etc/httpd/conf/httpd.conf SetOutputFilter DEFLATE//调用一个叫DEFL ...
- HDU 4400 Mines(好题!分两次计算距离)
http://acm.hdu.edu.cn/showproblem.php?pid=4400 题意: 在笛卡尔坐标中有多个炸弹,每个炸弹有一个坐标值和一个爆炸范围.现在有多次操作,每次引爆一个炸弹,问 ...
- Oracle imp导入数据
拿到别人给的dmp文件如何导入自己的库中呢?上码: 代码: imp dms/123321@orcl file=F:\TP_ZG_20171208.DMP feedback=10000 buffer=1 ...
- http协议的状态码解释
一些常见的状态码为: 200 – 服务器成功返回网页 404 – 请求的网页不存在 503 – 服务器超时 下面提供 HTTP 状态码的完整列表.点击链接可了解详情.您也可以访问 HTTP 状态码上的 ...
- 【六】php 错误异常处理
错误异常处理 概念:代码在try代码块被调用执行,catch代码块捕获异常 异常需要手动抛出 throw new Exception (‘message’,code) throw将出发异常处理机制 在 ...
- Java 通过get post 请求url
1️⃣.已获取小程序的access_token 为例,通过Get请求url import com.alibaba.fastjson.JSONObject; String wechatUrl = &qu ...
- VC.时间_ZC测试代码
1. #include <windows.h> #include <stdio.h> void TimeNowZ( char* _pc ) { SYSTEMTIME sys; ...
- 消息队列rabitMq
rabbitmq MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们.消息 ...