Android实现LIstView条目单选和多选RadioButton
来源:互联网 发布:优化好的单机游戏 编辑:程序博客网 时间:2024/06/13 14:58
看效果图是不是你想要的
![](file:///C:\Users\dell\Documents\Tencent Files\1065594610\Image\C2C\FB6AE53C25E13F7A05421784CF886785.png)
![](file:///C:\Users\dell\Documents\Tencent Files\1065594610\Image\C2C\FB6AE53C25E13F7A05421784CF886785.png)
![](file:///C:\Users\dell\Documents\Tencent Files\1065594610\Image\C2C\FB6AE53C25E13F7A05421784CF886785.png)
ListView的布局
<ListView android:choiceMode="singleChoice" android:background="#fff" android:layout_marginTop="5dp" android:id="@+id/listview_template" android:layout_above="@id/ll" android:layout_width="match_parent" android:layout_height="match_parent"/>其中choiceMode的属性很重要 选择模式.再没有发现这个属性的时候,我们一般会把选中的添加到一个Map中(position,true或false),然后在取出值进行判断是否有选中,
ListView的选择模式有4中分别是
1,CHOICE_MODE_NONE 普通模式
2,CHOICE_MODE_SINGIE单选模式
3,CHOICE_MODE_MULTIPLE多选模式
4,CHOICE_MODE_MULTIPLE_MODAL多选模式
也可以在代码中设置这4个属性值
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGIE);
下面是item的布局里面包含一个RadioButton
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="7dp" android:paddingBottom="7dp" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_marginLeft="12dp" android:textSize="@dimen/textSize_Eighteen" android:id="@+id/template_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="模板1"/> <RadioButton android:checked="false" android:clickable="false" android:focusableInTouchMode="false" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:focusable="false" android:layout_gravity="center_vertical" android:layout_marginRight="12dp" android:id="@+id/chickbutton" android:button="@drawable/chickbox_quipment_bg_selector" android:layout_width="wrap_content" android:layout_height="wrap_content"/></RelativeLayout>getView方法
@Overridepublic View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = View.inflate(SelectWatermarkActivity.this, R.layout.view_template, null); } TextView name = (TextView) convertView.findViewById(R.id.template_name); final RadioButton radioButton = (RadioButton) convertView.findViewById(R.id.chickbutton); if (selectPosition == position) { radioButton.setChecked(true); } else { radioButton.setChecked(false); } TemplateBean.ResponseBean bean = mResponse.get(position); name.setText(bean.getTemplateName()); return convertView;}其中selectPosition是用户选择条目的变量
再用户点击条目的时候进行初始化
@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectPosition = position; mAdapter.notifyDataSetChanged();}好了使用choiceMode属性可以很简单的实现单选和多选功能
阅读全文
0 0
- Android实现LIstView条目单选和多选RadioButton
- android-------listview 实现radiobutton 单选
- Listview+RadioButton实现单选
- listview和imageview实现条目单选效果
- listview和imageview实现条目单选效果
- [Android实例] 重写ListView控件实现RadioButton单选
- Android ListView+RadioButton实现单选的方法
- Android:ListView(列表)与RadioButton实现列表单选
- 实现listview里radiobutton单选
- ListView 中使用RadioButton实现单选
- ListView+radioButton实现每行单选
- ListView配合RadioButton实现单选列表
- ListView的条目单选和多选
- ListView利用CheckedTextViewr实现条目单选效果
- Radiobutton实现单选。
- Android ListView中点击单行实现RadioButton的单选功能,自定义Item布局文件
- Android开发,listview+radiobutton实现单选(选项可编辑)
- 在ListView的Item中使用RadioButton实现单选
- 目标检测:Improving Object Detection With One Line of Code
- js与JQuery的某些方法
- spring+springmvc+mybatis+jsp练习
- Mybatis 单例获取SqlSessionFactory
- SPARQL(一)
- Android实现LIstView条目单选和多选RadioButton
- MATLAB 深度学习:自编码(含MATLAB)
- 元素的显示方式
- jQuery的三种$()
- 使用SimpleDateFormate转换日期出错
- 轻量级分布式 RPC 框架
- 姿态检测整理--06-Associative Embedding: End-to-End Learning for Joint Detection and Grouping
- 使用 pycharm 远程运行server 上代码
- MR--InputSplit