android对话框,checkBox,同一时候在同一个页面上保存数据
package com.example.selectonlyonle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText editText;
private final static int DIALOG = 1;
boolean[] flags = new boolean[] { false, false, false, false };// 初始复选情况
String[] items = null;
private String lv_items[] = { "轮胎(400)", " 无骨雨刷(100)", "刹车片(235)",
"刹车盘(500)" };
private String lv_items_value[] = { "400", "100", "235", "500" };
private String result;
private int motoal;
private String test;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
items = getResources().getStringArray(R.array.hobby);
editText = (EditText) findViewById(R.id.editText);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// 显示对话框
showDialog(DIALOG);
}
});
}
/**
* 创建复选框对话框
*/
@Override
public Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DIALOG:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// 设置对话框的图标
// builder.setIcon(R.drawable.header);
// 设置对话框的标题
builder.setTitle("复选框对话框");
builder.setMultiChoiceItems(R.array.hobby, flags,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
flags[which] = isChecked;
System.out.println(which+"==which==="+which);
result = "您选择了:";
// for (int i = 0; i < flags.length; i++) {
if (flags[which]) {
result = result + items[which] + "、";
motoal = motoal
+ Integer
.valueOf(lv_items_value[which]);
System.out.println(result + "======"
+ motoal);
// test = test +lv_items_value[i];
}
// }
if (!flags[which]) {
// 假设选中了又不选了
motoal = motoal
- Integer
.valueOf(lv_items_value[which]);
System.out.println("==motoal=0="
+ motoal);
}
// for (int a = 0; a < 4; a++) {
// if (flags[a] == false) {
// motoal = motoal
// - Integer
// .valueOf(lv_items_value[a]);
// System.out.println("==motoal=0="
// + motoal);
// }
// }
// System.out.println("========="+test);
// editText.setText(motoal+"");
editText.setText(motoal + "");
}
});
// builder.setPositiveButton(result,
// new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int which) {
// }
// });
// 加入一个确定button
builder.setPositiveButton(" 确 定 ",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// 创建一个复选框对话框
dialog = builder.create();
break;
}
return dialog;
}
}
----------------------array.xml---------------------------------
<?xml version="1.0" encoding="utf-8"?
>
<resources>
<string-array name="hobby">
<item>轮胎(400)</item>
<item>无骨雨刷(100)</item>
<item>刹车片(235)</item>
<item>刹车盘(500)</item>
</string-array>
</resources>
这是看着网上的代码,仅仅是稍加了自己的理解。以及checkbox中数据的加减
------------------------------activity_main.xml-----------
<?xml version="1.0" encoding="utf-8"?
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:editable="false"
android:text="" />
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="显示复选框对话框" />
</LinearLayout>
android对话框,checkBox,同一时候在同一个页面上保存数据的更多相关文章
- 临时存存储页面上的数据---Web存储
HTML5 Web存储的两种方法使用 localStorage和sessionStorage 参考: http://www.cnblogs.com/taoweiji/archive/2012/12/0 ...
- 22SpringMvc_jsp页面上的数据传递到控制器的说明
假设有这个一个业务:在jsp页面上写入数据,然后把这个数据传递到后台. 效果如下:
- 14Flutter StatefulWidget有状态组件、页面上绑定数据、改变页面数据、实现计数器功能、动态列表
/** * Flutter StatefulWidget有状态组件.页面上绑定数据.改变页面数据 * 在Flutter中自定义组件其实就是一个类,这个类需要继承StatelessWidget/Stat ...
- 【Android Developers Training】 26. 在SQL数据库中保存数据
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- Android 学习笔记之如何使用SQLite数据库来保存数据...
PS:最近一阵子都在为考试复习...坑爹的计算机网络,复习了3天,最后该不会的还是不会...明天还考英语...真蛋疼... 学习内容: 1.使用SQLite数据库来保存数据... SQLite: ...
- Flutter StatefulWidget 有状态组件、页面上绑定数据、改变页面数据
在 Flutter 中自定义组件其实就是一个类,这个类需要继承 StatelessWidget/StatefulWidget. StatelessWidget 是无状态组件,状态不可变的 widget ...
- StatelessWidget 无状态组件 StatefulWidget 有状态组件 页面上绑定数据、改变页面数据
一.Flutter 中自定义有状态组件 在 Flutter 中自定义组件其实就是一个类,这个类需要继承 StatelessWidget/StatefulWidget. StatelessWidget ...
- Android通过网页打开App到指定页面并传递数据
首先在 Android Manifest 文件中注册 intent-filter <activity android:name=".MainActivity" android ...
- 多个 label checkbox 组合 显示在同一个水平线上[前提Bootstrap框架]
<th align="left" valign="middle"> <label class="checkbox inline fo ...
随机推荐
- java_Collection_详细介绍
转自:http://blog.sina.com.cn/s/blog_3fb3625f0101aref.html 1.类集框架 java.util 包中包含了一些在 Java 2 中新增加的最令人兴奋的 ...
- Unity3D如何减少安装包大小
译官方文档:http://docs.unity3d.com/Manual/ReducingFilesize.html PDF文档:http://www.rukawa.cn/Uploads/Attach ...
- 简单的后台管理系统vue-cli3.0+element-ui
前段时间在研究一个分发系统,发现vue-cli+element-ui好像是挺不错的,然后自己根据那个分发系统尝试搭建了一下 1.首先安装vue和vue-cli // 全局安装vue npm insta ...
- dell 1464 升级固态硬盘ssd 记录
2010年买的Dell 1464(i5 M430)用了4年多,感觉这款机器各方面性能还不错,决定给它升升级.目前笔记本最大的瓶颈应该出在机械硬盘的速度上,于是撑着双十一促销之际买了一块PLEXTOR/ ...
- Labeled Faces in the Wild 人脸识别数据集 部分测试数据
development test set Note: images displayed are original (non-aligned/funneled) images. match pairs ...
- 运算符重载,浅拷贝(logical copy) ,vs, 深拷贝(physical copy),三大件(bigthree problem)
一般的我们喜欢这样对对象赋值: Person p1;Person p2=p1; classT object(another_object), or A a(b); classT object = ...
- mysql之子查询
所谓子查询,就是指在一个查询之中嵌套了其他的若干查询,通过子查询可以实现多表查询,该查询语句中可能包含IN,ANY,ALL和EXISTS等关键字,除此之外还可以包含比较运算符,子查询经常出现在WHER ...
- mongodb pymongo.errors.CursorNotFound: Cursor not found, cursor id: 82792803897
默认 mongo server维护连接的时间窗口是十分钟 默认 单次从 server获取数据是101条或者 大于1M小于16M的数据 所以默认情况下,如果10分钟内未能处理完数据,则抛出该异常. 解决 ...
- 【Networking】(转)一个非常好的epoll+线程池服务器Demo
(转)一个非常好的epoll+线程池服务器Demo Reply 转载自:http://zhangyafeikimi.javaeye.com/blog/285193 [cpp] /** 张亚霏修改 文件 ...
- 在Docker和Kubernetes上运行MongoDB微服务
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟.容器是完全使用沙箱机制,相互之间不会有任何接 ...