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,同一时候在同一个页面上保存数据的更多相关文章

  1. 临时存存储页面上的数据---Web存储

    HTML5 Web存储的两种方法使用 localStorage和sessionStorage 参考: http://www.cnblogs.com/taoweiji/archive/2012/12/0 ...

  2. 22SpringMvc_jsp页面上的数据传递到控制器的说明

    假设有这个一个业务:在jsp页面上写入数据,然后把这个数据传递到后台. 效果如下:

  3. 14Flutter StatefulWidget有状态组件、页面上绑定数据、改变页面数据、实现计数器功能、动态列表

    /** * Flutter StatefulWidget有状态组件.页面上绑定数据.改变页面数据 * 在Flutter中自定义组件其实就是一个类,这个类需要继承StatelessWidget/Stat ...

  4. 【Android Developers Training】 26. 在SQL数据库中保存数据

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  5. Android 学习笔记之如何使用SQLite数据库来保存数据...

    PS:最近一阵子都在为考试复习...坑爹的计算机网络,复习了3天,最后该不会的还是不会...明天还考英语...真蛋疼... 学习内容: 1.使用SQLite数据库来保存数据... SQLite:   ...

  6. Flutter StatefulWidget 有状态组件、页面上绑定数据、改变页面数据

    在 Flutter 中自定义组件其实就是一个类,这个类需要继承 StatelessWidget/StatefulWidget. StatelessWidget 是无状态组件,状态不可变的 widget ...

  7. StatelessWidget 无状态组件 StatefulWidget 有状态组件 页面上绑定数据、改变页面数据

    一.Flutter 中自定义有状态组件 在 Flutter 中自定义组件其实就是一个类,这个类需要继承 StatelessWidget/StatefulWidget. StatelessWidget ...

  8. Android通过网页打开App到指定页面并传递数据

    首先在 Android Manifest 文件中注册 intent-filter <activity android:name=".MainActivity" android ...

  9. 多个 label checkbox 组合 显示在同一个水平线上[前提Bootstrap框架]

    <th align="left" valign="middle"> <label class="checkbox inline fo ...

随机推荐

  1. Power Desginer系列02【转载】

    在概念模型中主要有以下几个操作和设置的对象:实体(Entity).实体属性 (Attribute).实体标识(Identifiers).关系(Relationship).继承(Inheritance) ...

  2. C# 动态装载 DLL

    C# 动态装载 DLL LoadDllTool.cs 如下: using System; using System.Collections.Generic; using System.Text; us ...

  3. 转:修改Android签名证书keystore的密码、别名alias以及别名密码

    转自:http://blog.k-res.net/archives/1671.html 二月 5, 2014  |  Posted by K-Res   之前在测试Eclipse ADT的Custom ...

  4. (C++)浅谈using namespace std

    1.<iostream>和<iostream.h> 在你的编译器include文件夹里面可以看到,二者是两个文件,里面的代码是不一样的. 后缀为.h的头文件c++标准已经明确提 ...

  5. DoxygenToolkit.vim

    DoxygenToolkit.vim 常用命令: 光标在函数上,用 :Dox 自动生成函数的说明. 光标在文件头,用 :DoxAthor 自动生成文件说明. 下载地址

  6. ipv6相关

    link-local和site-local address http://blog.163.com/s_u/blog/static/13308367201052411431027/ 学习IPV6的时候 ...

  7. android java 设计模式详解 Demo

    android java 设计模式详解 最近看了一篇设计模式的文章,深得体会,在此基础我将每种设计模式的案例都写成Demo的形式,方便读者研究学习, 首先先将文章分享给大家: 设计模式(Design ...

  8. 手动脱UPX 壳实战

    作者:Fly2015 Windows平台的加壳软件还是比較多的,因此有非常多人对于PC软件的脱壳乐此不彼,本人菜鸟一枚,也学习一下PC的脱壳.要对软件进行脱壳.首先第一步就是 查壳.然后才是 脱壳. ...

  9. excel 根据单元格内容自动调整列宽

      excel 根据单元格内容自动调整列宽 CreateTime--2018年5月28日08:49:40 Author:Marydon 1.情景展示 单元格宽度超过了列宽 2.解决方案 第一步:同时选 ...

  10. spring AOP编程--AspectJ注解方式

    1. AOP 简介 AOP(Aspect-Oriented Programming, 面向切面编程): 是一种新的方法论, 是对传统 OOP(Object-Oriented Programming, ...