viewholder的使用
Adapter的作用就是ListView界面与数据之间的桥梁,当列表里的每一项显示到页面时,都会调用Adapter的getView方法返回一个View。
优化的思路两种:
1. View的重用
View的每次创建是比较耗时的,因此对于getview方法传入的convertView应充分利用 != null的判断
2.ViewHolder的应用
View的findViewById()方法也是比较耗时的,因此需要考虑只调用一次,之后就用View.getTag()方法来获得ViewHolder对象。
package com.example.android_listview_activity; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; /** * @desc 自定义适配器 * @author ljt * @time 2014年8月27日 上午11:15:27 */ public class MainActivity5 extends Activity{ private static final String TAG = "MainActivity"; private ListView listView; private ImageView imageView; private TextView textView; private ViewHolder holder; private int[] images = {R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light, R.drawable.abc_ic_go_search_api_holo_light,R.drawable.abc_ic_go_search_api_holo_light }; private String[] names = {"北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海", "北京","上海" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView)this.findViewById(R.id.listView1); MyAdapter adapter = new MyAdapter(); listView.setAdapter(adapter); } /** * @desc 自定义适配器 * @author ljt * @time 2014年8月27日 上午11:09:13 */ class MyAdapter extends BaseAdapter{ /** * How many items are in the data set represented by this Adapter. */ @Override public int getCount() { return names.length; } /** * Get the data item associated with the specified position in the data set. */ @Override public Object getItem(int position) { return names[position]; } /** * Get the row id associated with the specified position in the list. */ @Override public long getItemId(int position) { return position; } /** * 创建列表项 */ @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i(TAG, "position == "+position); if(null == convertView){ // 将layout的xml布局文件实例化为View类对象 convertView = getLayoutInflater().inflate(R.layout.source2,null); imageView = (ImageView)convertView.findViewById(R.id.imageView3); imageView.setImageResource(images[position]); textView = (TextView)convertView.findViewById(R.id.textView3); textView.setText(names[position]); holder = new ViewHolder(); holder.imageView = imageView; holder.textView = textView; convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); holder.imageView.setImageResource(images[position]); holder.textView.setText(names[position]); } return convertView; } } class ViewHolder{ private ImageView imageView; private TextView textView; } }
相关推荐
Thesis 1.7 – Wordpress Theme.zip Introducing the Thesis Theme for WordPress Thesis is a search engine optimized ...
JumboCAD EDA is professional schematic & PCB layout software. JumboCAD EDA include 3 packages. JumboCAD Schematic Capture, JumboCAD PCB designer & JumboCAD Library editor
匿名发布了所有正式发布的MS主题的反汇编版本(Royale / Zune / Embedded等),这些反汇编版本只是插入到现有的源代码中,然后将作为常规构建的一部分进行构建,并对layout.inx,它们也可以自动包含在我们的版本中。...
*) And it is a fixed layout which means even on my big screen I have to scroll all the way down and have to scan for it. There have to be a better way, obviously. The alternative Rails documentation ...
•Zend Framework 1.7 •Zend Framework 1.6 •Zend Framework 1.5 •Zend Framework 1.0 •Zend Framework 0.9 •Zend Framework 0.8 •Zend Framework 0.6 •Zend Framework Coding Standard for PHP •...
Section 1.7. Dependency Properties Section 1.8. Resources Section 1.9. Styles and Control Templates Section 1.10. Graphics Section 1.11. Application Deployment Section 1.12. Where Are We? ...
1.7 CREATE PURCHASE GROUP 8 2. BASIC SETUP 10 2.1 DEFINE SCREEN LAYOUT OF MATERIAL MASTER 10 2.2 DEFINE MATERIAL TYPE 11 2.3 SETUP MATERIAL NUMBER RANGE 13 2.4 DEFINE MATERIAL GROUP 14 2.5 SETUP ...
• layout:修复当鼠标光标快速离开的时候展开的面板不会被折叠的问题; • tagbox:修复tagbox框和label标签不在 一条直线上的问题。 Improvement(改进) • combo:'inputEvents'属性自带'blur'事件处理器; ...
#Gephi-ForceLayout要运行此jar文件,应使用Java 1.7。 ##用法:java -jar gephi-toolkit-demos2-1.0-SNAPSHOT-jar-with-dependencies.jar input_seq.fas input_vector.csv output1.txt output2.txt output3.txt ...
layout:添加“unsplit”和“split”方法; messager:支持键盘导航功能; form:添加“onChange”事件; combobox:添加“queryParams”属性; slider:添加“range”属性; menu:添加“itemHeight”,...
一个支持多种状态的自定义视图,可以方便的切换到:加载中视图错误视图空数据视图网络异常视图内容视图使用dependencies { implementation ' com.classic.common:multiple-status-view:1.7 '}示例< ...
PASCAL VOC是一个图像集,由Mark Everingham (University ofLeeds)、Luc van Gool (ETHZ, Zurich)等人创立,有1.7W+张图片,分为20类。PASCALVOC竞赛也是计算机视觉竞赛的鼻祖,从2005年到2012年一共举办了8届,包含...
编译java时遇到import com.borland.dbswing.*; import com.borland.dx.sql.dataset.*; import com.borland.jbcl.layout.*; 不存在,把这几个包放在jdk/jre/lib/ext 下就解决了
PCIE转千兆网RTL8111H(S)芯片硬件参考设计 Cadence原理图+PDF原理图+芯片数据手册:' RTL8111G_.DSN rtl8111g_.opj RTL8111G_16.DSN RTL8111G_16.opj rtl8111g_series_8111h_series_...RTL8111H(S)_Layout_Guide_1.0.pdf
1.7. Symbol和Renderer 159 1.7.1. 如何为一个层设置Simple Renderer 159 1.7.2. 如何为一个层设置UniqueValue Renderer 161 1.7.3. 如何为一个层设置ClassBreaks Renderer 165 1.7.4. 如何为一个层设置...
PCIE转千兆网RTL8111H(S)硬件参考设计( Cadence原理图+PDF原理图)+芯片数据手册等资料 RTL8111G_.DSN rtl8111g_.opj RTL8111G_16.DSN RTL8111G_16.opj rtl8111g_series_8111h_...RTL8111H(S)_Layout_Guide_1.0.pdf
PCIE转千兆网RTL8111H(S)芯片硬件参考设计 Cadence原理图+转ALTIUM格式原理图+芯片数据手册,仅供学习及设计参考。 Imported RTL8111G_16.PRJPCB(转AD版) RTL8111G_.DSN ...RTL8111H(S)_Layout_Guide_1.0.pdf
3) 微带带通滤波器:带内波纹:0.1dB 中心频率:2GHZ 下边频:1.7GHZ 上边频:2.3GHZ 在2.8GHZ频率点衰减>30dB 4) 射频放大器:工作频率:2GHZ 增益:>20dB 带宽:>100MHZ 噪声系数: 完成微带低通滤波器,功率分配器...
1.7. Modifying the Default Styles of Tool Bar 1.8. Dialog Bar 1.9. Resizable Dialog Bar Deriving New Class from CDialogBar Resizing Edit Control Dynamic Layout Using the New Class 1.10. Adding Flyby ...
5. 产品修改记录:记录了MD7105-A06 Preliminary的修改记录,从1.2到1.7版本的修改记录,包括Rx灵敏度规格的更新、BOM的更新、操作电压的修改、公司名称的修改等。 6. 重要声明:AMICCOM保留对产品或服务的修改或...