Blog / 阅读

android优化listview

by admin on 2014-03-21 19:02:08 in ,



public class AppManagerAdapter extends BaseAdapter {  
    private static final String TAG = "AppManagerAdapter";  
    private List<AppInfo> appinfos;  
    private Context context;  
    <strong><span style="font-size:18px;">//把要创建的ImageView和TextView定义在外面成静态</span></strong>  
    private static ImageView iv;  
    private static TextView tv;  
  
    public AppManagerAdapter(List<AppInfo> appinfos, Context context) {  
        this.appinfos = appinfos;  
        this.context = context;  
    }  
  
    public int getCount() {  
        // TODO Auto-generated method stub  
        return appinfos.size();  
    }  
  
    public Object getItem(int position) {  
        // TODO Auto-generated method stub  
        return appinfos.get(position);  
    }  
  
    public long getItemId(int position) {  
        // TODO Auto-generated method stub  
        return position;  
    }  
  
<strong><span style="font-size:18px;">/** 
 * View convertView (转化view对象 ,历史view对象的缓存) convertview 就是拖动的时候被回收掉的view对象 
 */</span></strong>  
    public View getView(int position, View convertView, ViewGroup parent) {  
        AppInfo info = appinfos.get(position);  
        View view;  
        if (convertView == null) {  
             Log.i(TAG,"通过资源文件 创建view对象");  
            view = View.inflate(context, R.layout.app_item, null);  
        } else {  
             Log.i(TAG,"使用历史缓存view对象");  
            view = convertView;  
        }  
        iv = (ImageView) view.findViewById(R.id.iv_app_icon);  
        tv = (TextView) view.findViewById(R.id.tv_app_name);  
        iv.setImageDrawable(info.getIcon());  
        tv.setText(info.getAppname());  
        return view;  
  
    }  
}  


写评论

相关文章

上一篇:android刷新listview列表

下一篇:android 代码优化:关闭输出日志

评论

写评论

* 必填.

分享

栏目

赞助商


热门文章

Tag 云