BaseAdapter中getView中改动的地方:

@Override
public View getView(int position, View contentView, ViewGroup arg2) {
TextView textview;
ImageView imageView;
//判断contentView是否为空,为空重新创建
if(contentView == null){
contentView =layoutInflater.inflate(R.layout.list_item, null);
textview=(TextView)contentView.findViewById(R.id.textview);
textview.setText((CharSequence) list.get(position).get("name"));
imageView=(ImageView)contentView.findViewById(R.id.imageview);
imageView.setImageResource((Integer) list.get(position).get("pictrue"));
}else{
//contentView不为空,返回已经存在的contentView
return contentView;
}

获取数据源中改动的地方:

MainActivity.java中的getData();

private List<Map<String, Object>> getData() {
// TODO Auto-generated method stub List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "图1");
map.put("pictrue", R.drawable.tu1);
list.add(map); map = new HashMap<String, Object>();
map.put("name", "图2");
map.put("pictrue", R.drawable.tu2);
list.add(map); map = new HashMap<String, Object>();
map.put("name", "图3");
map.put("pictrue", R.drawable.tu3);
list.add(map); map = new HashMap<String, Object>();
map.put("name", "图4");
map.put("pictrue", R.drawable.tu4);
list.add(map); map = new HashMap<String, Object>();
map.put("name", "图5");
map.put("pictrue", R.drawable.tu5);
list.add(map); map = new HashMap<String, Object>();
map.put("name", "图6");
map.put("pictrue", R.drawable.tu6);
list.add(map); map = new HashMap<String, Object>();
map.put("name", "图7");
map.put("pictrue", R.drawable.tu7);
list.add(map); map = new HashMap<String, Object>();
map.put("name", "图8");
map.put("pictrue", R.drawable.tu8);
list.add(map); return list;
}

Listview之优化BaseAdapter中的getView中的contentView的更多相关文章

  1. Listview性能优化

    首先,虽然大家都知道,还是提一下,利用好 convertView 来重用 View,切忌每次 getView() 都新建.ListView 的核心原理就是重用 View.ListView 中有一个回收 ...

  2. ListView getView中放置多个item和getItemViewType的用法

    ListView 和 Adapter 的基础 工作原理: ListView 针对List中每个item,要求 adapter “给我一个视图” (getView). 一个新的视图被返回并显示 如果我们 ...

  3. ListView中的item中的Onclick事件的优化

    ListView的Adapter的优化布局载入器的载入次数最典型的使用方法是使用convertView进行优化,让convertView当做布局载入器的载体,也就是.重用 convertView 用以 ...

  4. BaseAdapter以及对ListView的优化(转)

    背景 对于ListView.GridView.Gallery.Spinner等等,它是它们的适配器,直接继承自接口类Adapter的,使用BaseAdapter时需要重写很多方法,其中最重要的当属ge ...

  5. Android ListView使用BaseAdapter与ListView的优化 (转至 http://www.open-open.com/lib/view/open1339485728006.html)

    在ListView的使用中,有时候还需要在里面加入按钮等控件,实现单独的操作.也就是说,这个ListView不再只是展示数据,也不仅仅是这一行要来处理用户的操作,而是里面的控件要获得用户的焦点.读者可 ...

  6. Android -- 重写BaseAdapter以及对ListView的优化

    背景 对于ListView.GridView.Gallery.Spinner等等,它是它们的适配器,直接继承自接口类Adapter的,使用BaseAdapter时需要重写很多方法,其中最重要的当属ge ...

  7. Activity中与ListActivity中使用listview区别

    Activity中与ListActivity中使用listview区别 一.Activity中与ListActivity中使用listview区别(本身没多大区别,只是ListActivity在lis ...

  8. hive优化之——控制hive任务中的map数和reduce数

    一.    控制hive任务中的map数: 1.    通常情况下,作业会通过input的目录产生一个或者多个map任务.主要的决定因素有: input的文件总个数,input的文件大小,集群设置的文 ...

  9. Android之ListView性能优化——一行代码绑定数据——万能适配器

    如下图,加入现在有一个这样的需求图,你会怎么做?作为一个初学者,之前我都是直接用SimpleAdapter结合一个Item的布局来实现的,感觉这样实现起来很方便(基本上一行代码就可以实现),而且也没有 ...

随机推荐

  1. ios app 支持 ipv6-only

    最近苹果公司发布声明:自今年6月1日开始,所有提交至苹果App Store的应用申请必须要兼容面向硬件识别和网络路由的最新互联网协议--IPv6-only标准. 那么问题来了,目前的app是否支持ip ...

  2. 解决PhoneGap不支持viewport的几种方法

    前几天用phonegap编译GameBuilder+CanTK时,发现HTML里的viewport无效.CanTK根据devicePixelRatio检测设备的DPI,然后用viewport设置正确的 ...

  3. AOP 之 6.1 AOP基础(拾陆)

    6.1.1  AOP是什么 考虑这样一个问题:需要对系统中的某些业务做日志记录,比如支付系统中的支付业务需要记录支付相关日志,对于支付系统可能相当复杂,比如可能有自己的支付系统,也可能引入第三方支付平 ...

  4. CSS:static/relative/absolute

    static - default and this is the FLOW. ------------------------------------------------------------- ...

  5. 对Linux新手非常有用的 20个命令

    你打算从Windows换到Linux上来,还是你刚好换到Linux上来?哎哟!!!我说什么呢,是什么原因你就出现我的世界里了.从我以往的经验来说,当我刚使用Linux,命令,终端啊什么的,吓了我一跳. ...

  6. S2 第二章数据库的实现

    实现增删改查代码 1 select * from student --增加数据 insert into student (name,banji,xuehao) values(,) --修改数据 upd ...

  7. Sudoku Solver [LeetCode]

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  8. Java 集合系列 08 Map架构

    java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...

  9. 问题解决The connection to adb is down, and a severe error has occured.

    遇到问题描述: 运行android程序控制台输出 [2013-06-25 11:10:32 - MyWellnessTracker] The connection to adb is down, an ...

  10. uva 10723

      10723 - Cyborg Genes Time limit: 3.000 seconds Problem F Cyborg Genes Time Limit 1 Second Septembe ...