I made an app and I' am showing images in ListView
. I have the height of the list item small and after a few insertions in the 9th item of the list is showing the first one I inserted. Why is that happening?
I think the problem isn't in the databse because when I clicked the item and open up the details screen is the proper image in it.
I can't figure what is the problem! Any ideas?
My Adapter is :
public class CustomAdapter extends BaseAdapter {
private List<Clothes> items;
private Context context;
private LayoutInflater inflater;
public CustomAdapter(Context _context, List<Clothes> _items){
inflater = LayoutInflater.from(_context);
this.items = _items;
this.context = _context;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Clothes clothes = items.get(position);
View view = convertView;
if (view == null) {
view = inflater.inflate(R.layout.cloth_item, null);
TextView category = (TextView) view.findViewById(R.id.tv_category);
TextView size = (TextView) view.findViewById(R.id.tv_size);
TextView style = (TextView) view.findViewById(R.id.tv_style);
TextView brand = (TextView) view.findViewById(R.id.tv_brand);
TextView state = (TextView) view.findViewById(R.id.tv_state);
ImageView photo = (ImageView) view.findViewById(R.id.list_image);
category.setText(clothes.getCategory());
size.setText(clothes.getSize());
style.setText(clothes.getStyle());
brand.setText(clothes.getBrand());
state.setText(clothes.getState());
photo.setImageBitmap(BitmapFactory.decodeFile(clothes.getPhotograph()));
}
return view;
}
}
And my list is :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#ffffff">
<ListView
android:id="@+id/categorized_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fastScrollEnabled="true"
/>
</RelativeLayout>