listview

Listview和checkbox多选

删除回忆录丶 提交于 2020-03-12 16:36:16
在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作。表面上看上去只是改变checkbox那么简单,然而实际开发中,实现起来并不是那么得心应手。尤其当listview比较多(比如屏幕最多只能显示10个item,但总共有12个item,也就是说listview的item数大于屏幕能够显示的item数)滑动屏幕的时候,由于适配器中getview()会重复使用被移除屏幕的item,所以会造成checkbox选择状态不正常的现象。自己在开发中碰到这样的问题很是苦恼,查了下资料,发现网上很少没有针对这类批量操作并没有一个完整的例子。搜了很多篇帖子才完美的实现这一常用的操作。所以在这里把这个Demo贴出来,供大家参考,希望能对大家有所帮助。 主界面的布局main.xml 这个就不多说什么 <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:layout_width="fill_parent" android:layout_height="100dip" android:text="原创:Simtice QQ:512375320

Android开发进阶 -- 通用适配器 CommonAdapter

感情迁移 提交于 2020-03-12 09:41:50
在Android开发中,我们经常会用到ListView 这个组件,为了将ListView 的内容展示出来,我们会去实现一个Adapter来适配,将Layout中的布局以列表的形式展现到组件中。   比如,像 GGTalk 安卓版的查找用户功能,会把符合条件的用户都列在下面: 为了达到这个效果,我们需要实现一个自定义的Adapter,而其它地方的ListView也要实现一个Adapter,这些Adapter会有很多重复的代码,非常繁琐,现在我就将重复代码封装到了一个通用的适配器CommonAdapter中,这样,在使用时只要继承CommonAdapter就可以了,如此就避免了大段代码的重复,让代码更简洁易懂。我们先来看看CommonAdapter的定义。   一.CommonAdapter 实现 public abstract class CommonAdapter<T> extends BaseAdapter { private List<T> dataList; protected Context context; protected int item_layoutId=0; protected HashMap<Integer,Integer> layoutIdMap; //多种itemView时用到。 第一个int对应type类型,第二个int对应 itemlayoutId /

android ListView 在初始化时多次调用getView()原因分析

余生颓废 提交于 2020-03-11 07:58:27
今天在做一个功能:在初始化ListView时,把第一行背景置为黄色,同时保存第一行对象,用于在点击其他行时将该行重新置为白色。 if(position==0){ convertView.setBackgroundColor(Color.YELLOW); lastconvertView=convertView; } 结果运行时发现第一行的颜色一直会是黄色而无法改变。调试了之后发现getView中 if(position==0) 居然会多次进入,最终导致的结果便是我最后一次取得的lastconvertView并非listview上面的第一行。网上查了之后发现原因是因为未固定listview的高度导致的,但是root cause却找不到说明。于是去翻阅了源码+大量调试,大概推算出了原因,在此记录。 首先是说明下ListView的显示机制,listview的机制是这样子的: 假如你有1000条数据,但是屏幕只能显示10条,那么当你第一次加载显示的时候,会先创建10个View,1-10,当你拖动Listview,使1隐藏而11显示的时候,系统会自动把填充1的View传递过来,注意看代码Adapter的getView方法 @Override public View getView(final int position, View convertView, ViewGroup parent)

CListCtrl控件的使用指南

和自甴很熟 提交于 2020-03-08 11:22:13
创建图形列表并和CListCtrl关联: m_image_list.Create(IDB_CALLER2, 16, 10, RGB(192,192, 192)); m_image_list.SetBkColor( GetSysColor( COLOR_WINDOW ) ); m_caller_list.SetImageList( &m_image_list, LVSIL_SMALL); 为报表添加4列: char *szColumn[]={"昵称","IP地址","登陆时间","状态"}; int widths[]={100,98,70,55}; LV_COLUMN lvc; lvc.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; lvc.fmt=LVCFMT_LEFT; for(int i=0;i<4;i++) {//插入各列 lvc.pszText=szColumn[i]; lvc.cx=widths[i]; lvc.iSubItem=i; m_caller_list.InsertColumn(i,&lvc); } 为报表添加两项,以附加方式添加: char* data[4]; data[0]="所有人"; data[1]="0.0.0.0"; data[3]="在线"; data[2]=new char; CTime now

flutter listview 设置分割线

。_饼干妹妹 提交于 2020-03-06 16:05:17
使用ListView.separated,就很简单了 ListView.separated( scrollDirection: direction, itemBuilder: (context, index) { final Axis slidableDirection = direction == Axis.horizontal ? Axis.vertical : Axis.horizontal; return _getSlidableWithLists(context, index, slidableDirection); }, itemCount: list.length, separatorBuilder: (BuildContext context, int index) => Divider(height: 1.0, color: AppColors.separator), ); 如果使用ListView.builder,没有这个属性,需要自己在itemBuilder中增加下划线 ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemBuilder: (BuildContext context, int index) => GroupContactItem(

求java代码把listview中的新增item每次都添加到第0行

一个人想着一个人 提交于 2020-03-06 11:01:16
在做一个把crashlog显示到指定listview的小工具,显示是显示出来了,但是每次新增的crashlog都自动加到listview的最后一位,用了Collections.reverse()只是把表面文件名倒了过来,里面的数据还是不动,想要把每次新增的crashlog都加到第0行,请教大佬该怎么做 private void inflateListView(File[] files) { List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>> (); for (int i = 0; i < files.length; i++) { Map<String, Object> listItem = new HashMap<String, Object> (); if (files[i].isDirectory()) { // 如果是文件夹就显示的图片为文件夹的图片 listItem.put(“aicon”, R.drawable.arrow_down); } else { listItem.put(“aicon”, R.drawable.arrow_up); } // 添加一个文件名称 listItem.put("filename", files[i].getName()); File

Alternate row color ListView xamarin forms

淺唱寂寞╮ 提交于 2020-03-06 09:01:32
问题 I have bind on my ListView, an ObersvableCollection. And i want to alternate my row color of my ListView. I found lot of code, but didn't work for me... If you can share an example/sample ! Like this : But i don't know how i can do that ? I work with Visual Studio 2015 / Xamarin forms. My project must be work with Android and IOS. Thank for your help! 回答1: There's no built in way to do this with XF. The simplest approach would be to include an Index property in your Item model (you would have

Android设计模式系列--之适配器模式

大兔子大兔子 提交于 2020-03-05 21:46:43
quote frome: http://www.cnblogs.com/qianxudetianxia/archive/2012/02/27/2010965.html 对于android开发者来说起,适配器模式简直太熟悉不过,有很多应用可以说是天天在直接或者间接的用到适配器模式,比如ListView。 ListView用于显示列表数据,但是作为列表数据集合有很多形式,有Array,有Cursor,我们需要对应的适配器作为桥梁,处理相应的数据(并能形成ListView所需要的视图)。 正是因为定义了这些适配器接口和适配器类,才能使我们的数据简单灵活而又正确的显示到了adapterview的实现类上。 适配器模式,Adapter Pattern,勇敢的去适配,大量的资源可以重用。 1.意图 适配器模式,把一个类的接口变换成客户端所期待的另一种接口,从而使原本不匹配而无法在一起工作的两个,类能够在一起工作。 适配器模式分为类适配器模式和对象适配器模式。 关于类适配器模式,因为java的单继承,如果继承一个类,另外的则只能是接口,需要手动实现相应的方法。 热门词汇: 类的适配器模式 对象的适配器模式 缺省适配器模式 源类 目标接口 2.结构图和代码 为了简明直接,我省略了相关的其他适配器 ,只以此两个适配器为例。 ListViews做为client,他所需要的目标接口(target

Listview refresh without notifyDataSetChange

半世苍凉 提交于 2020-03-05 04:05:30
问题 There is a problem with notifyDataSetChanged. I have a list which retrieves data from sqlite database. The problem is that I know that I have to call notifyDataSetChanged everytime I use add method of list class. I can't understand why my list shows data after addAll() calling without the notifyDataSetChange(). I also tried using add() but result is the same. I need answer because I want to understand very well how notifyDataSetChange() works. Fragment code: public static List<Wherehouse>

Listview refresh without notifyDataSetChange

|▌冷眼眸甩不掉的悲伤 提交于 2020-03-05 04:05:14
问题 There is a problem with notifyDataSetChanged. I have a list which retrieves data from sqlite database. The problem is that I know that I have to call notifyDataSetChanged everytime I use add method of list class. I can't understand why my list shows data after addAll() calling without the notifyDataSetChange(). I also tried using add() but result is the same. I need answer because I want to understand very well how notifyDataSetChange() works. Fragment code: public static List<Wherehouse>