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 ...
随机推荐
- EventStore .NET API Client在使用线程池线程同步写入Event导致EventStore连接中断的问题研究
最近,在使用EventStore的.NET Client API采用大量线程池线程同步写入Event时(用于模拟ASP.NET服务端大并发写入Event的情况),发现EventStore的连接会随机中 ...
- linux系统安装gcc
安装nginx时会遇到错误提示gcc: command not found,需要先安装gcc 在centos7上安装成功. # yum group list # yum group install & ...
- django单表操作 增 删 改 查
一.实现:增.删.改.查 1.获取所有数据显示在页面上 model.Classes.object.all(),拿到数据后,渲染给前端;前端通过for循环的方式,取出数据. 目的:通过classes(班 ...
- jQuery调用WebService
1.编写4种WebService方法 [WebService(Namespace = "http://tempuri.org/")] [WebServiceBindi ...
- Kettle中根据一个输入行派生出多个输出行
依然在北京,早上停电了,整个人感觉对不好了,接下来就说一下在使用ETL工具kettle做数据校验的时候遇到的一些问题,一级解决方案. 1:数据校验效果图下图: 原始表数据(需要校验的表数据) 对上表数 ...
- Cognos10.2.1配置加密信息不能被加密
好奇心害死猫,可是我不是猫.这个问题已经不是第一次出现了,之前是从10.1.1到10.2.0出现的,这次是从10.2.0到10.2.1出现的,上次由于时间的问题被搁置了,这次竟然再次遇到同样的问题,已 ...
- windows 7 64bit安装apche php
http://windows.php.net/download#php-5.6-ts-VC11-x64http://www.apachehaus.com/cgi-bin/download.plx 下载 ...
- 很全的Python 面试题 github
https://github.com/taizilongxu/interview_python
- 非阻塞I/O
http://blog.163.com/tyw_andy/blog/static/1167902120099163252164/ 套接口缺省是阻塞的.这一点意味着当发出一个不能立即完成的套接口调用时, ...
- 判断IE浏览器版本的精简脚本
IE浏览器不管是什么版本,总是跟Web标准有些不太兼容.对于代码工作者来说,自然是苦不堪言,为了考虑IE的兼容问题,不管是写 CSS 还是 JS,往往都要对 IE 特别对待,这就少不了做些判断.本文不 ...