- 浏览: 320776 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
crxiang:
写得很好啊,最近正好需要这个,谢谢分享了!
Android中ProgressDialog的简单示例 -
shangs2010:
分析的真仔细,多谢!
SharePreference类似于JavaEE中的session -
guochongcan:
fantaxy025025 写道兄弟,你这个不行的。
只能删 ...
MYSQL用一条SQL语句删除重复记录 -
fantaxy025025:
兄弟,你这个不行的。只能删除 重复个数是2的,如果重复个数大于 ...
MYSQL用一条SQL语句删除重复记录 -
wujiandong:
不错,多写点这方面的东西~~,加油~~,哥们~~
布局学习——妙用TabHost
主要是讲checkbox的使用,其实接触过html都应该知道表单中checkbox选择按钮,在这里我在一个activity中添加4个checkbox和一个button主要是通过button触发事件获取选中的checkbox中的值,我定义了一个checkbox.xml的应该layout布局
<?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"> <CheckBox android:id="@+id/plain_cb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Plain" /> <CheckBox android:id="@+id/serif_cb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Serif" /> <CheckBox android:id="@+id/bold_cb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bold" /> <CheckBox android:id="@+id/italic_cb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Italic" /> <Button android:id="@+id/getValue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="获取CheckBox值" /> </LinearLayout>
下面是实现代码 :
public class CheckBoxActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.checkbox); final CheckBox plain = (CheckBox) findViewById(R.id.plain_cb); final CheckBox serif = (CheckBox) findViewById(R.id.serif_cb); final CheckBox bold = (CheckBox) findViewById(R.id.bold_cb); final CheckBox italic = (CheckBox) findViewById(R.id.italic_cb); Button getValue = (Button) findViewById(R.id.getValue); getValue.setOnClickListener(new OnClickListener() { public void onClick(View v) { String title = "你选择了"; if (plain.isChecked()) { title += "plain"; } if (serif.isChecked()) { title += "serif"; } if (bold.isChecked()) { title += "bold"; } if (italic.isChecked()) { title += "italic"; } setTitle(title); } }); } }
==========================================================
下面是另一个
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text="@+id/TextView01" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <CheckBox android:text="@+id/CheckBox01" android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> <CheckBox android:text="@+id/CheckBox02" android:id="@+id/CheckBox02" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> <CheckBox android:text="@+id/CheckBox03" android:id="@+id/CheckBox03" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> <CheckBox android:text="@+id/CheckBox04" android:id="@+id/CheckBox04" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> <Button android:text="@+id/Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </LinearLayout>
public class CheckBoxDemo extends Activity { private TextView m_txtView; private CheckBox m_CheckBox1; private CheckBox m_CheckBox2; private CheckBox m_CheckBox3; private CheckBox m_CheckBox4; private Button m_Button; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); m_txtView = (TextView) this.findViewById(R.id.TextView01); m_CheckBox1 = (CheckBox) this.findViewById(R.id.CheckBox01); m_CheckBox2 = (CheckBox) this.findViewById(R.id.CheckBox02); m_CheckBox3 = (CheckBox) this.findViewById(R.id.CheckBox03); m_CheckBox4 = (CheckBox) this.findViewById(R.id.CheckBox04); m_txtView.setText("调查:你喜欢Android是因为什么原因?"); m_CheckBox1.setText("好看"); m_CheckBox2.setText("好用"); m_CheckBox3.setText("免费"); m_CheckBox4.setText("应用广泛"); m_CheckBox1.setOnCheckedChangeListener(m_checkboxListener); m_CheckBox2.setOnCheckedChangeListener(m_checkboxListener); m_CheckBox3.setOnCheckedChangeListener(m_checkboxListener); m_CheckBox4.setOnCheckedChangeListener(m_checkboxListener); m_Button = (Button) this.findViewById(R.id.Button01); m_Button.setOnClickListener(m_BtnListener); m_Button.setText("提交"); } private OnClickListener m_BtnListener = new OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub if (arg0.getId() == R.id.Button01) { int value = 0; if (m_CheckBox1.isChecked()) { value++; } if (m_CheckBox2.isChecked()) { value++; } if (m_CheckBox3.isChecked()) { value++; } if (m_CheckBox4.isChecked()) { value++; } Toast.makeText(getBaseContext(), "你选择了 " + value + "项", Toast.LENGTH_SHORT).show(); } } }; private CheckBox.OnCheckedChangeListener m_checkboxListener = new CheckBox.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (buttonView.getId() == R.id.CheckBox01) { if (isChecked) { Toast.makeText(getBaseContext(), "CheckBox 01 check ", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(), "CheckBox 01 ucheck ", Toast.LENGTH_SHORT).show(); } } if (buttonView.getId() == R.id.CheckBox02) { if (isChecked) { Toast.makeText(getBaseContext(), "CheckBox 02 check ", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(), "CheckBox 02 ucheck ", Toast.LENGTH_SHORT).show(); } } if (buttonView.getId() == R.id.CheckBox03) { if (isChecked) { Toast.makeText(getBaseContext(), "CheckBox 03 check ", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(), "CheckBox 03 ucheck ", Toast.LENGTH_SHORT).show(); } } if (buttonView.getId() == R.id.CheckBox04) { if (isChecked) { Toast.makeText(getBaseContext(), "CheckBox 04 check ", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(), "CheckBox 04 ucheck ", Toast.LENGTH_SHORT).show(); } } } }; }
发表评论
-
使用 SharedPreferences
2013-01-31 21:37 1175SharedPreferences是一种轻量级的数据存储 ... -
android:windowSoftInputMode属性详解
2012-11-01 07:36 801android:windowSoftInputMode ac ... -
自定义ListView中的分割线
2012-11-01 07:12 2268ListView中每个Item项之间都有分割线,设置andro ... -
Android中Bitmap和Drawable
2012-10-24 17:54 956一、相关概念 1、Drawable就是一个可画的对象,其可能 ... -
在EditText/TextView中插入表情图片、样式、下划线等
2012-09-23 20:03 2664EditText: 通常用于显示 ... -
Android开发:在EditText中关闭软键盘
2012-09-23 14:41 17711、EditText有焦点(focusable为true) ... -
Android 字体和颜色
2012-06-23 18:34 941对于能够显示文字的控件(如TextView EditText ... -
解决Eclipse Indigo(3.7)中文字体偏小问题
2012-06-04 20:33 1077===========转============= ... -
Android中Cursor 的一些方法
2012-05-16 17:15 1417close() //关闭游标,释放资源 copyStrin ... -
ContentProvider分析
2012-05-15 22:24 974红色部分较重要的 private static ... -
Java的log 的几种表示颜色
2012-05-09 16:12 0Log下面的日志颜色 E Error 红 ... -
android单元测试时,异常情况解决记录
2012-04-07 20:26 1506异常内容 java.lang.NoClassDefFo ... -
Android_SDK及ADT升级方法
2012-04-05 10:57 25381本文只讲如何 ... -
android 退出程序 对话框提醒
2012-03-17 20:23 0if (keyCode == KeyEvent.KEYCO ... -
DBA应该具有什么样的素质?——转
2012-03-17 20:18 0问题起源于在写一份材 ... -
抓住移动互联网发展最佳时机,开发最好的移动应用程序,为用户提供最佳的软件服务
2012-03-04 20:03 0抓住移动互联网发展最佳时机,开发最好的移动应用程序,为用户提供 ... -
Android WebView 浏览器
2012-01-01 09:38 4164WebView的使用很方便。在学习WebView之前,我 ... -
android ImageView的scaleType属性
2011-12-27 13:07 1161ImageView:Displays an arbitra ... -
程序实现线性布局相关
2011-12-26 15:42 1017程序实现线性布局相关1、 LinearLayout l ... -
Android中Toast的用法简介
2011-12-24 21:20 1380Toast是Android中用来显示显示信息的一种机制,和Di ...
相关推荐
android CheckBox的使用简单实例。
简单实现自定义checkbox控件四种选择状态的图片样式
Android中Selsetor选中时改变CheckBox背景,在开发中非常常用,我们通常会用到单选框,多选框,在实际项目中,默认的颜色不会满足我们的要求,所以,我们需要自己设置,这是我写的一个例子希望能和大家交流学习
本demo实现功能为:Expandablelistview子项checkBox先获取已选择状态,在次过程中可修改子项选择,最终提交选择子类的项,并打印相关数据
android listview和checkbox联合使用,选中和取消
这是我自己写的android listview里面使用checkbox的demo
适用于初步学习Android移动开发,学习Android的CheckBox控件。里边也有相关Toast的简单应用。
Android自定义checkbox的代码
Android 带有切换动画的CheckBox
最近公司需求做个员工报餐界面用到多个CheckBox 行列
<item name="android:button">@drawable/selector</item>//这个selector.xml中就是对应不同状态的CheckBox的背景图片 3:在selector.xml <selector xmlns:android=...
ListView+CheckBox写的可以进行多选,反选,删除,全选这些功能。进去CheckBox隐藏,长按ListView的一项,CheckBox显示出来,底部的多选,反选,删除,全选也显示出来。
android checkbox 的isChecked属性
拥有三种状态纯Material风格的Android Checkbox控件
在Android中动态获取recyclerView中checkBox的值,然后在activity或者fragment获取check的值。
Android完美解决ListView复用导致的Checkbox状态混乱问题,具体见博客 http://www.jianshu.com/p/744dcca03a99
Android checkbox 实现单选,代码较少,布局简单
android checkbox全选反选
CircleCheckBox Screenshot: Attrs attr format ...CircleCheckBox is available in the MavenCentral, so getting it as simple as adding it as a ...checkBox.setListener(new CircleCheckBox.On
用Android写的树形结构多选CheckBox工具,代码简单,拿来就可以使用,这是我优化后可以直接当工具使用的DEMO。