Reputation: 1728
Ive included my listview adapter's code below all works fine except the image isnt loaded from the url. What might be the case. I'm using the Android Query library for loading images.
public Onadapter(Context context,String[] id,String[] label,String[] title,String[] image,String[] hrs,String[] posted_date)
{
this.context=context;
this.id = id;
this.label = label;
this.title = title;
this.image = image;
this.hrs = hrs;
this.posted_date=posted_date;
}
private class ViewHolder{
ImageView img;
TextView id;
TextView label;
TextView title;
TextView hrs;
TextView posted_date;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.whatslist, null);
holder = new ViewHolder();
holder.id=(TextView) convertView.findViewById(R.id.whats_id);
holder.img = (ImageView) convertView.findViewById(R.id.thumb1);
holder.label= (TextView) convertView.findViewById(R.id.label);
holder.title = (TextView) convertView.findViewById(R.id.artist_e_desc);
holder.hrs = (TextView) convertView.findViewById(R.id.hrs);
holder.posted_date = (TextView) convertView.findViewById(R.id.date);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.id.setText(id[position]);
holder.label.setText(label[position]);
holder.title.setText(title[position]);
holder.hrs.setText(hrs[position]);
holder.posted_date.setText(posted_date[position]);
imgaq = new AQuery(convertView);
imgaq.id(holder.img).image(image[position], true, true, 0, 0, null, AQuery.FADE_IN_NETWORK, 1.0f);
return convertView;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return image.length;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
}
Upvotes: 3
Views: 3143
Reputation: 76
Maybe you'd better using recycle()
I think it's not good way new everytime in getView() method.
AQuery listAq = new AQuery(this);
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.whatslist, null);
holder = new ViewHolder();
holder.id=(TextView) convertView.findViewById(R.id.whats_id);
holder.img = (ImageView) convertView.findViewById(R.id.thumb1);
holder.label= (TextView) convertView.findViewById(R.id.label);
holder.title = (TextView) convertView.findViewById(R.id.artist_e_desc);
holder.hrs = (TextView) convertView.findViewById(R.id.hrs);
holder.posted_date = (TextView) convertView.findViewById(R.id.date);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.id.setText(id[position]);
holder.label.setText(label[position]);
holder.title.setText(title[position]);
holder.hrs.setText(hrs[position]);
holder.posted_date.setText(posted_date[position]);
AQuery imgaq = listAq.recycle(convertView);
imgaq.id(holder.img).image(image[position], true, true, 0, 0, null, AQuery.FADE_IN_NETWORK, 1.0f);
return convertView;
}
Upvotes: 5
Reputation: 1728
Turns out i was incorrectly referencing the xml resource for imageview.Silly me :D
Upvotes: 0
Reputation: 7226
I would write this line:
imgaq = new AQuery(convertView);
in the constructor of the adapter and pass context to AQuery constructor instead of the view. Especially that convertView sometimes is null so you are initializing AQuery with null
public Onadapter(Context context,String[] id,String[] label,String[] title,String[] image,String[] hrs,String[] posted_date)
{
this.context=context;
this.id = id;
this.label = label;
this.title = title;
this.image = image;
this.hrs = hrs;
this.posted_date=posted_date;
this.aq = new AQuery(context);
}
Upvotes: 0