android优化——adapter
什么是Adapter,可以先看看我的上一篇文章,Android开发——说说Adapter那点事 Adapter与View的连接主要依靠getView这个方法返回我们需要的自定义view。ListView是Android app中一个最最最常用的控件了,所以如何让ListView流畅运行,获取良好的用户体验是非常重要的。对ListView优化就是对Adapter中的getView方法进行优化。09年的Google IO大会给出的优化建议如下:
Adapter优化示例代码:
@Override public View getView(int position, View convertView, ViewGroup parent) { Log.d("MyAdapter", "Position:" + position + "---" + String.valueOf(System.currentTimeMillis())); ViewHolder holder; if (convertView == null) { final LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.list_item_icon_text, null); holder = new ViewHolder(); holder.icon = (ImageView) convertView.findViewById(R.id.icon); holder.text = (TextView) convertView.findViewById(R.id.text); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.icon.setImageResource(R.drawable.icon); holder.text.setText(mData[position]); return convertView; } static class ViewHolder { ImageView icon; TextView text; }
以上是Google io大会上给出的优化建议,经过尝试ListView确实流畅了许多。
转至:http://www.cnblogs.com/halzhang/archive/2010/12/05/1896791.html
相关推荐
wangkuifeng0 2011-04-18
wellfly 2020-01-10
绿豆饼 2019-10-20
89550492 2011-09-13
喝绿茶的猫 2015-05-30
llzhangfly 2012-11-26
Colphin 2019-06-28
onlyring的文档库 2012-05-31
康 2014-12-12
lxypeter 2010-09-17
guanguanmeng 2019-06-21
XiaoMuFireAnt 2009-09-02
vincent 2012-03-05
柒青衿 2011-12-27
leverage00 2016-06-23
NASA00 2013-04-06
yuyu00 2013-01-28
quickisbest 2013-01-22