I have a custom listview which within the list row layout has a SmartImageView (http://loopj.com/android-smart-image-view/)
I am trying to set each SmartImageView on each row to a picture, below is my list adapter.
private class MyListAdapter extends ArrayAdapter<ListItem> {
private ArrayList<ListItem> items;
public MyListAdapter(Context context, int textViewResourceId, ArrayList<ListItem> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.item_row_layout, null);
}
ListItem o = items.get(position);
if (o != null) {
TextView title = (TextView) v.findViewById(R.id.ptitle);
TextView site = (TextView) v.findViewById(R.id.site);
TextView price = (TextView) v.findViewById(R.id.price);
SmartImageView img = (SmartImageView) findViewById(R.id.smallimage);
Typeface font = Typeface.createFromAsset(getAssets(), "Asap-Regular.ttf");
site.setTypeface(font);
title.setTypeface(font);
price.setTypeface(font);
if (title != null) {
title.setText(o.getTitle());
}
if (site != null) {
site.setText("Supplier Name");
}
if (price != null) {
price.setText("£"+ String.valueOf(o.getPrice()));
}
if (img != null){
String url = o.getImage();
img.setImageUrl(url);
}
}
return v;
}
}
All other things get set alright i.e title, price etc however the images do not get set correctly.
If there is more than one list item than the top item will get the last items image, and the rest has no image set. While if there is one item in the list it does not get a image set at all.
If you need any more of the code or information do let me know!