ListView重写Adapter优化上下滚动响应速度

主要是重写Adapter的getView方法,执行时不用每次都创建一次对象。

// Music list adapter public static class MusicListAdapter extends SimpleAdapter { private LayoutInflater mInflater; private List<? extends Map<String, ?>> mList; public MusicListAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); mInflater = LayoutInflater.from(context); mList = data; } @Override public int getCount() { // TODO Auto-generated method stub return super.getCount(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return super.getItem(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return super.getItemId(position); } @Override public View getView(int position, View convertView, ViewGroup parent) { // 优化list速度 ViewHolder holder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.list_items, null); holder = new ViewHolder(); holder.ItemTitle = (TextView) convertView.findViewById(R.id.ItemTitle); holder.ItemSinger = (TextView) convertView.findViewById(R.id.ItemSinger); holder.ItemTime = (TextView) convertView.findViewById(R.id.ItemTime); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.ItemTitle.setText((String)mList.get(position).get("ItemTitle")); holder.ItemSinger.setText((String)mList.get(position).get("ItemSinger")); holder.ItemTime.setText((String)mList.get(position).get("ItemTime")); return convertView; } static class ViewHolder { TextView ItemTitle; TextView ItemSinger; TextView ItemTime; } }

你可能感兴趣的:(优化,ListView,String,list,null,Class)