android优化listview
public class AppManagerAdapter extends BaseAdapter { private static final String TAG = "AppManagerAdapter"; private List<AppInfo> appinfos; private Context context; //把要创建的ImageView和TextView定义在外面成静态 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; } /** * View convertView (转化view对象 ,历史view对象的缓存) convertview 就是拖动的时候被回收掉的view对象 */ 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; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。