此代码加载带有图像的列表视图,文本视图引用它并编辑以供您使用(来自惰性适配器的示例代码)
public class abcdadapter extends BaseAdapter {
private Activity activity;
private String[] data;
private ArrayList<HashMap<String, String>> dat;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public abcdadapter(Activity a, ArrayList<HashMap<String, String>> save,String[] images) {
activity = a;
dat=save;
data=images;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView text;
public ImageView image;
}
public View getView(int position, View convertView, ViewGroup parent) {
return parent;
View vi=convertView;
ViewHolder holder;
if(convertView==null){
vi = inflater.inflate(R.layout.item, null);
holder=new ViewHolder();
holder.text=(TextView)vi.findViewById(R.id.text);
holder.image=(ImageView)vi.findViewById(R.id.image);
vi.setTag(holder);
}
else
holder=(ViewHolder)vi.getTag();
holder.text.setText(dat.get(position).get("NAME"));
// holder.image.setTag(data[position]); // set your image from drawable
// imageLoader.DisplayImage(data[position], activity, holder.image);
return vi;
}