栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

具有包含CheckBoxes的自定义适配器的Listview

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

具有包含CheckBoxes的自定义适配器的Listview

答案中的代码有效,但效率很低(实际上,您可以看到它,只需滚动

ListView
并检查
Logcat
即可看到垃圾收集器正在工作)。下面是一种改进的
getView
回收视图的方法:

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {     LinearLayout view = (LinearLayout) convertView;     if (view == null) {          view = (LinearLayout) inflater.inflate(R.layout.record_view_start, parent, false);     }     TextView tv = (TextView) view.findViewById(R.id.engName);     tv.setText(getItem(position));     CheckBox cBox = (CheckBox) view.findViewById(R.id.checkBox1);     cBox.setTag(Integer.valueOf(position)); // set the tag so we can identify the correct row in the listener     cBox.setChecked(mChecked[position]); // set the status as we stored it  cBox.setonCheckedChangeListener(mListener); // set the listener         return view;}onCheckedChangeListener mListener = new onCheckedChangeListener() {     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mChecked[(Integer)buttonView.getTag()] = isChecked; // get the tag so we know the row and store the status      }};

关于您问题中的代码,起初我认为这是错误的,因为您设置行的方式不同,但是我不明白为什么当您从列表中分离行视图时适配器会有这种行为。另外,我什至测试了代码,它在

CheckBoxes
(但内存处理非常差)方面表现很好。也许您正在做其他事情使适配器无法工作?



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/573891.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号