【发布时间】:2016-01-21 19:13:42
【问题描述】:
我制作了一个应用程序,并在ListView 中显示图像。我的列表项的高度很小,在列表的第 9 项中插入几次后,显示我插入的第一个项。为什么会这样?
我认为问题不在数据库中,因为当我单击该项目并打开详细信息屏幕时,其中的图像是正确的。
我不知道是什么问题!有什么想法吗?
我的适配器是:
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;
}
}
而我的清单是:
<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>
【问题讨论】:
-
使用视图持有者绑定列表中的视图
-
查看这个问题..这会有所帮助stackoverflow.com/questions/6470089/…
-
谢谢大家!是的,只是持有者创造了奇迹!!!!