int 和integer的误用导致 listview的不刷新
来源:互联网 发布:数据挖掘系统的任务 编辑:程序博客网 时间:2024/05/22 14:04
今天犯了一个低级的错误,对int 和integer的使用没有正确。
遇到的情况是这样的:我要刷新listview,可是数据已经重新设置,就是没有刷新,当时数据是这样处理的:
private Map<Integer, MusicInfo> mSelectMap;public void removeDeleteData(List<MusicInfo> musicInfos) {// TODO Auto-generated method stubIterator iterator = mSelectMap.entrySet().iterator();while(iterator.hasNext()){Map.Entry e=(Map.Entry)iterator.next();Integer key = (Integer) e.getKey();musicInfos.remove(key.intValue());System.out.println(e.getKey()+"="+e.getValue()+"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");}Log.d("pzc", musicInfos.size() + "<<<<<<<<<<<<<<<<<<<<");mMusicInfos = musicInfos;//notifyDataSetChanged();}}
目的就是要重原有的musicInfos数据中删除mSelectMap中有的数据,但是上面的代码有什么问题呢?
问题就在于
Integer key = (Integer) e.getKey();musicInfos.remove(key.intValue());
musicInfos.remove(int arg0)和musicInfos.remove(object arg0);两种方法,我们要的是musicInfos.remove(int arg0)这个,而使用上面代码走的却是musicInfos.remove(object arg0),导致我的数据一直保持原样,没有更新,为什么呢?
因为integer是int的封装,它是一个对象。
java.lang.Integer是一个类.对它的操作要通过类的方法
int是JAVA缺省的8中基本数据类型之一.不是类的对象.
int是基本数据类型,Integer是对int进行了封装的一个类。
0 0
- int 和integer的误用导致 listview的不刷新
- int 和 Integer 的区别
- int 和 Integer 的区别
- int和Integer的区别
- int和Integer的区别
- int 和 integer的区别
- Integer和int的区别
- Integer 和 int 的区别
- int和integer的区别
- int和Integer的区别
- int 和integer的区别
- int和Integer的不同
- int 和 Integer的区别
- int 和integer的区别
- int 和integer的区别
- Integer和Int的区别
- int 和integer的区别
- int 和integer的区别
- 抓取网页时,常用到的正则语法。(持续更新,本次2015-11-11)
- zookeeper简单配置使用
- 自定义控件(11)---Canvas的平移、旋转、缩放、错切、Matrix直接变换Canvas
- 移动硬盘“脱机”(签名冲突)的硬盘如何正常使用
- Java word文件创建
- int 和integer的误用导致 listview的不刷新
- Lua中强大的元方法__index详解
- 双击返回键退出应用
- Calculation method running time
- css3的各种用法的地址,方便以后查询
- tomcat的maxThreads、acceptCount(最大线程数、最大排队数)
- display:none与visible:hidden的区别
- ssi框架的简单搭建
- Android 对ScrollView滚动监听,实现美团、大众点评的购买悬浮效果