ListView 实现多选/单选
http://blog.csdn.net/ljfbest/article/details/40685327
ListView自身带了单选、多选模式,可通过listview.setChoiceMode来设置:
listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);//开启多选模式listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);//开启单选模式listview.setChoiceMode(ListView.CHOICE_MODE_NONE);//默认模式listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);//没用过,不知道用来干嘛的
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable="@color/c1" android:state_pressed="true"/>
- <item android:drawable="@color/c1" android:state_checked="true"/>
- <item android:drawable="@color/c2"/>
- </selector>
但是单选选中时的颜色还是系统选中的颜色,而不是自己设定的c1,不知道为什么?
- public class CheckableLinearLayout extends LinearLayout implements Checkable {
- private boolean mChecked;
- public CheckableLinearLayout(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- @Override
- public void setChecked(boolean checked) {
- mChecked = checked;
- setBackgroundDrawable(checked ? new ColorDrawable(0xff0000a0) : null);//当选中时呈现蓝色
- }
- @Override
- public boolean isChecked() {
- return mChecked;
- }
- @Override
- public void toggle() {
- setChecked(!mChecked);
- }
- }
- <com.ljfbest.temp.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <TextView
- android:id="@+id/tv"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:minHeight="?android:attr/listPreferredItemHeightSmall"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:textAppearance="?android:attr/textAppearanceListItemSmall" />
- </com.ljfbest.temp.CheckableLinearLayout>
获取选中条目的ids,是long[]类型,注意需要adapter的hasStableIds()返回true,并且这些id是adapter的
getItemId(int position)返回的.demo中有演示
listview.setItemChecked(position, value);//设置某行的状态
ListView 实现多选/单选的更多相关文章
- ListView 实现多选/无线电
ListView本身与无线电.多选模式.由listview.setChoiceMode设置: listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE) ...
- vue开发购物车,解决全选单选问题
实现全选单选,在vue中无法通过this获取input中的checkbox的checked属性,但是可以通过vue对input的特殊方式v-model来实现对应数据的绑定,同样也可以通过这种方式实现购 ...
- Android在listview添加checkbox实现单选多选操作问题(转)
转自:http://yangshen998.iteye.com/blog/1310183 在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上 ...
- Android在listview添加checkbox实现单选多选操作问题
android根据View的不同状态更换不同的背景http://www.eoeandroid.com/thread-198029-1-1.html android 模仿朋友网推出的菜单效果[改进版]h ...
- 完美解决Android在listview添加checkbox实现单选多选操作问题
在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上看上去只是改变checkbox那么简单,然而实际开发中,实现起来并不是那么得心应手.尤其当 ...
- Android 带checkbox的listView 实现多选,全选,反选,删除
activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- Android 带checkbox的listView 实现多选,全选,反选
由于listview的一些特性,刚开始写这种需求的功能的时候都会碰到一些问题,重点就是存储每个checkbox的状态值,在这里分享出了完美解决方法: 布局文件: [html] <?x ...
- bootstrap 列表 表格 表单 复选 单选 多选 输入框组
一.列表 ul li 二.表格 table (http://www.runoob.com/bootstrap/bootstrap-tables.html) 1. 基本表格 <table cla ...
- 邮箱性质--全选单选的操作和传值 用属性的name传值
封装类 using System; using System.Collections.Generic; using System.Web; /// <summary> /// Ha 的摘要 ...
随机推荐
- c#中字符串截取使用的方法
AndyZhang welcome to java world c#中字符串截取使用的方法 String substring(int beginIndex) String substring(int ...
- Android 系统日期时间的获取
import java.text.SimpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月 ...
- java汉字转拼音以及得到首字母通用方法
package oa.common.utils; import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.piny ...
- java常见机试题目(1)
好久没写博客了,今天重新开始,发现自己学习的知识很糙,就是知道,也能说出来,但是很多知识点不清晰,不深入,所以呢,写个博客总结一些程序,理清概念. 1java中大小写字母转化,在java中存在api ...
- HDU 4135 Co-prime
思路:直接用求(b,1)范围内互质的数,(a-1,1)范围内互质的数.再求反 就是敲一下容斥模板 #include<cstdio> #include<cstring> #inc ...
- 判断html中的滚动条
在工作中需要调整jqgrid的列宽,但是不希望有横向滚动条,因为是固定的列宽,当显示区域缩小后,数据会出现竖型滚动条 这个时候需要判断竖型滚动条是否存在进行列宽的调整. 自己调查了一下,发现滚动条可以 ...
- Miller-Rabin素性测试(POJ3641)
一.概念引入 在以往判断一个数n是不是素数时,我们都是采用i从2到sqrt(n)能否整除n.如果能整除,则n是合数;否则是素数.但是该算法的时间复杂度为O(sqrt(n)),当n较大时,时间性能很差, ...
- devexpress中gridcontrol头部添加垂直线(右边框)
winform开发,用devexpress中的gridcontrol控件,头部默认是3D样式,当客户希望像内容一样扁平化显示且需要添加垂直线(右边框)时恶梦开始了..经过一阵摸索发现可以这样解决: 1 ...
- openssl pem转cer
openssl x509 -in cert/2120.pem -outform der -out cert/ios20170109.cer
- JS----JS调试技巧
骨灰级调试大师Alert 那还是互联网刚刚起步的时代,网页前端还主要以内容展示为主,浏览器脚本还只能为页面提供非常简单的辅助功能的时候.那个时候,网页主要运行在以IE6为主的浏览器中,JS的调试功能还 ...