安卓——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 ...
随机推荐
- computed 计算选项
computed 的作用主要是对原数据进行改造输出.改造输出:包括格式的编辑,大小写转换,顺序重排,添加符号……. 格式化输出结果 我们先来做个读出价格的例子:我们读书的原始数据是price:100 ...
- Python GIL(Global Interpreter Lock)
一.介绍 In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threa ...
- java泛型的作用和好处
转载于:https://blog.csdn.net/u012760183/article/details/52092692 之前参加面试的时候遇到面试官问泛型的作用,只是说了大概自己的理解, 在此转载 ...
- SE91 SAP消息类型
SE91 SAP消息类型 E:Error W:Warning I :Information A :Abortion S :Success 标准 : MESSAGE ID sy-msgid TYPE ...
- [从零开始搭网站四]CentOS配置Tomcat
点击下面连接查看从零开始搭网站全系列 从零开始搭网站 上一章带大家配置了JDK,那么现在就要来配置Tomcat容器了. 1:去 http://tomcat.apache.org/download-90 ...
- markdown一些网站
1.https://stackedit.io/editor 2.https://github.com/bioinformatist/LncPipeReporter 3.
- RN原生调用一:安卓Toast
首先安卓原生方法:Toast.makeText(getApplicationContext(), "默认的Toast", Toast.LENGTH_SHORT); 在RN中js如何 ...
- 【UOJ】#273. 【清华集训2016】你的生命已如风中残烛
题目链接:http://uoj.ac/problem/273 $${Ans=\frac{\prod _{i=1}^{m}i}{w-n+1}}$$ #include<iostream> #i ...
- 《剑指offer》第四十五题(把数组排成最小的数)
// 面试题45:把数组排成最小的数 // 题目:输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼 // 接出的所有数字中最小的一个.例如输入数组{3, 32, 321},则打印出这3 ...
- QT新建工程编译出现"Moc'ing xxx.h..." 找不到文件或者error MSB6006: "cmd.exe" exited with code 3.
产生这个问题的原因是QT的头文件路径包含出错: (1)如果没有添加如图所示的路径,则添加后重新编译: (2)如果已经添加了,则删除后,重新添加,在重新编译: (3)或者在QT Project Sett ...