ListView单选的实现总结(转)
今天在智能停车场项目中需要实现PullToRefreshListView的单选功能,考虑到分页,刷新等,以前的实现方式是采用自己维护一个集合保存选中位置的选中状态,但这个方式比较繁琐,今天采用了listview的单选模式
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);来实现:
package com.centrvideo.parkapp.adapter; import java.util.List; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; import com.centrvideo.parkapp.demain.ExportInfo; public class ExportAdapter extends MyBaseAdapter<ExportInfo, ListView> { public ExportAdapter(Context context, List<ExportInfo> list) { super(context, list); } @Override public View getView(int position, View covertView, ViewGroup group) { ChoiceListItemView view; if (covertView == null) { view = new ChoiceListItemView(context, null); } else { view = (ChoiceListItemView) covertView; } ExportInfo exportInfo = list.get(position); view.setData(exportInfo); return view; } }
package com.centrvideo.parkapp.adapter; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.CheckBox; import android.widget.Checkable; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.centrvideo.parkapp.R; import com.centrvideo.parkapp.demain.ExportInfo; import com.centrvideo.parkapp.util.ImageLoaderUtils; import com.lidroid.xutils.ViewUtils; import com.lidroid.xutils.view.annotation.ViewInject; public class ChoiceListItemView extends LinearLayout implements Checkable { @ViewInject(R.id.listview_export_image) private ImageView listview_export_image; @ViewInject(R.id.listview_export_entrytime) private TextView listview_export_entrytime; @ViewInject(R.id.listview_export_number) private TextView listview_export_number; @ViewInject(R.id.listview_entry_time) private TextView listview_entry_time; @ViewInject(R.id.cb_export) public CheckBox selectBtn; private ImageLoaderUtils imageLoaderUtils; public ChoiceListItemView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.listview_export, this, true); ViewUtils.inject(v); imageLoaderUtils = ImageLoaderUtils.newInstance(); } public void setData(ExportInfo exportInfo) { imageLoaderUtils.loadImage(exportInfo.getEntryimg(), listview_export_image, R.drawable.cell_hold); listview_export_entrytime.setText("入口时间:" + exportInfo.getEntrytime() + ""); listview_export_number.setText("车牌号码:" + exportInfo.getPlatenumber() + ""); listview_entry_time.setText("位置:" + exportInfo.getGatewayname() + ""); } @Override public boolean isChecked() { return selectBtn.isChecked(); } @Override public void setChecked(boolean checked) { selectBtn.setChecked(checked); //根据是否选中来选择不同的背景图片 if (checked) { selectBtn.setBackgroundResource(R.drawable.cheliangduibi_queding); } else { selectBtn.setBackgroundResource(0); } } @Override public void toggle() { selectBtn.toggle(); } }
![](https://yqfile.alicdn.com/img_51e409b11aa51c150090697429a953ed.gif)
//启用单选模式 listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); //获得选中结果;通过listView.getCheckedItemPosition();//活动被选中的位置 case R.id.tv_titlebar_right: if (CommonUtil.isFastDoubleClick()) { return; } int selectPosition = listView.getCheckedItemPosition(); CommonUtil.StartToast(ExportSureListActivity.this,"被选中的位置:"+selectPosition); ExportInfo exportInfo = list1.get(selectPosition-1);//注意这里需要减1 CommonUtil.StartToast(ExportSureListActivity.this,"被选中的位置:"+exportInfo.toString()); // intent = new Intent(ExportSureListActivity.this, // ChargeActivity.class); // startActivity(intent); break; }
![](https://yqfile.alicdn.com/img_51e409b11aa51c150090697429a953ed.gif)
http://www.cnblogs.com/xiaoxiao-study/p/a1e1561444542d99b70e781be488f35e.html
ListView单选的实现总结(转)相关推荐
- 项目总结(FDL)(一)ListView单选和多项
一.单选. 1.需求:ListView中各item中有一个CheckBox,点击个CheckBox记录item:如果已经记录,再次点击其他item,则之前记录的取消. ...
- ListView 自己定义BaseAdapter实现单选打勾(无漏洞)
ListView 自己定义BaseAdapter实现单选打勾(无漏洞) (假设须要完整demo,请评论留下邮箱) (眼下源代码已经不发送.假设须要源代码,加qq316701116.不喜勿扰) 近期由于 ...
- ListView单行选中变色
网上找了很多ListView选中后变色的文章,但都是什么字体设置变色选择器,要不就是ListView设置变色器,单行选中变色的始终找不到! 甚至还有人说用ListView的onItemSelected ...
- Flutter ListView使用
Flutter 小知识:ListView使用 ListView参数介绍 ScrollController的使用 ListTile ListView全选 ListView多选 ListView单选 Li ...
- Android使用SharedPreferences存储APP设置参数
一.什么是SharedPreferences? android.content.SharedPreferences是一个接口,用来获取和修改持久化存储的数据. Android数据持久化方法中最简单的一 ...
- Preference,PreferenceCategory,PreferenceList,PreferenceCheckBox等控件的简单讲解
有人会纳闷,为什么不使用普通的控件去写settings页面,非得要preference来写,这是有原因的,Preference可以自动保存上一次操作的值,并且preference会自动将自己的值保存在 ...
- Android在listview添加checkbox实现单选多选操作问题
android根据View的不同状态更换不同的背景 http://www.eoeandroid.com/thread-198029-1-1.html android 模仿朋友网推出的菜单效果[改进版] ...
- Android中ListView与RadioButton结合----自定义单选列表
有时候我们需要制作自定义的单选列表,但是会遇到一些问题,比如多选,假选问题,所以网上找了找资料,整理一个demo出来,贴一下代码: [html] view plaincopy <ListView ...
- Android RecyclerView、ListView实现单选列表的优雅之路.
一 概述: 这篇文章需求来源还是比较简单的,但做的优雅仍有值得挖掘的地方. 需求来源:一个类似饿了么这种电商优惠券的选择界面: 其实就是 一个普通的列表,实现了单选功能, 效果如图: (不要 ...
最新文章
- Linux系统查看位数和内存
- 区块链学习笔记:D03 区块链在各行业领域的应用(一)
- coreboot学习8:ramstage阶段之资源分配流程
- SlickEdit介绍
- Android studio开发一:三个页面简单实现QQ登录界面的延时跳转
- php获得视频文件扩展名,php 获取文件扩展名的 n 种方法
- 汉庭加盟:连锁酒店影视房的市场分析
- 【解决步骤】TortoiseGitPlink Fatal Error:No supported authentication methods available (server sent: publi
- 有效括号 python_1111. 有效括号的嵌套深度
- java LocalDateTime 加时间,计算两个时间的差
- 第一次见岳父岳母的攻略「转载」
- 【日语】secret base
- oracle awr 执行计划,AWR(五)-利用AWR生成SQL执行计划(SQLREPORT)并进行优化 | 信春哥,系统稳,闭眼上线不回滚!...
- c++小游戏合集(AI)
- xb格式数据库迁移处理
- 雷军十年的演讲:吾志所向,一往无前!
- 图神经网络-图与图学习笔记-1
- mt4 虚拟服务器,mt4模拟服务器地址
- 轻量级Kubernetes之k3s:2:使用docker作为容器运行环境
- matlab自带滤波器函数
热门文章
- cookies的详细使用说明
- POJ2118基础矩阵快速幂
- C语言经典例69-有n个人围成一圈报数问题
- 【Flutter】Flutter 混合开发 ( Flutter 与 Native 通信 | 在 Flutter 端实现 BasicMessageChannel 通信 )
- 【Android 安全】DEX 加密 ( Application 替换 | Android 应用启动原理 | Instrumentation 源码分析 )
- 【组合数学】非降路径问题 ( 非降路径问题概要说明 | 非降路径问题基本模型 | 非降路径问题拓展模型 1 非原点起点 | 非降路径问题拓展模型 2 有途经点 )
- 【Android 高性能音频】AAudio 音频流 数据回调细节 ( 数据回调函数优先级 | 数据回调函数 | 采样率 | 采样数 | 缓冲区调整 | 线程不安全 )
- 【嵌入式开发】C语言 内存分配 地址 指针 数组 参数 实例解析
- 同步、异步、阻塞、非阻塞
- PHP将英文数字转换为阿拉伯数字