我有问题。目前我正在使用Lazyloading将图像和数据加载到我的listview中使用arraylist。但是它只显示arraylist的最后一项。
以下是LazyLoading适配器类:
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<Hashtable<String,String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, ArrayList<Hashtable<String,String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView title;
public TextView author;
public TextView format;
public TextView call_number;
public ImageView cover_image;
public Button next;
public Button previous;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
ViewHolder holder;
if (convertView == null){
vi = inflater.inflate(R.layout.search_result_display_list , null);
holder=new ViewHolder();
holder.next = (Button) vi.findViewById(R.id.next);
holder.previous = (Button) vi.findViewById(R.id.previous);
holder.title = (TextView) vi.findViewById(R.id.item_title);
holder.author = (TextView) vi.findViewById(R.id.item_author);
holder.format = (TextView) vi.findViewById(R.id.item_format);
holder.call_number = (TextView) vi.findViewById(R.id.item_call_number);
holder.cover_image=(ImageView) vi.findViewById(R.id.cover_image);
vi.setTag(holder);
}
else {
holder=(ViewHolder)vi.getTag();
vi = convertView;
}
for(int i = 0; i < getCount(); i++) {
holder.title.setText(data.get(i).get("title"));
holder.author.setText(data.get(i).get("author"));
holder.format.setText(data.get(i).get("format"));
holder.call_number.setText(data.get(i).get("callNumber"));
holder.cover_image.setTag(data.get(i).get("coverImage"));
imageLoader.DisplayImage(data.get(i).get("coverImage"), activity, holder.cover_image);
}
return vi;
}
我认为问题实际上可能与我的for循环有关。它无限生成的地方。但我不知道在输入此代码时我在哪里出错了。请帮忙。
答案 0 :(得分:4)
在data.get(i)
使用position