ANDROID-ListView项目不';不能正常显示

ANDROID-ListView项目不';不能正常显示,android,listview,Android,Listview,我制作了一个应用程序,正在列表视图中显示图像。我的列表项的高度很小,在列表的第9项中插入几次后,将显示我插入的第一项。为什么会这样 我认为问题不在数据库中,因为当我单击项目并打开详细信息屏幕时,它中的图像是正确的 我不知道是什么问题!有什么想法吗 我的适配器是: public class CustomAdapter extends BaseAdapter { private List<Clothes> items; private Context context;

我制作了一个应用程序,正在
列表视图中显示图像。我的列表项的高度很小,在列表的第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>
公共类CustomAdapter扩展了BaseAdapter{
私人清单项目;
私人语境;
私人充气机;
公共CustomAdapter(上下文_上下文,列表_项){
充气器=从(_上下文)开始的充气器;
this.items=\u items;
this.context=\u context;
}
@凌驾
public int getCount(){
返回items.size();
}
@凌驾
公共对象getItem(int位置){
返回位置;
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
衣服=物品。获取(位置);
视图=转换视图;
如果(视图==null){
视图=充气机。充气(R.layout.cloth_项,空);
TextView类别=(TextView)view.findViewById(R.id.tv\u类别);
TextView大小=(TextView)view.findViewById(R.id.tv\u大小);
TextView样式=(TextView)view.findViewById(R.id.tv_样式);
TextView品牌=(TextView)view.findviewbyd(R.id.tv_品牌);
TextView状态=(TextView)view.findViewById(R.id.tv_状态);
ImageView照片=(ImageView)view.findViewById(R.id.list\u图像);
category.setText(costs.getCategory());
size.setText(costs.getSize());
style.setText(costs.getStyle());
brand.setText(costs.getBrand());
state.setText(costs.getState());
photo.setImageBitmap(BitmapFactory.decodeFile(costs.getphoto());
}
返回视图;
}    
}
我的清单是:

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>

布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="YourClass"
    tools:showIn="@layout/activity_notification">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listViewNotification" />
</RelativeLayout>

创建一个名为list_item.xml的文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ripple="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:id="@+id/notificationMain"
    android:gravity="center">

    <com.andexert.library.RippleView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/rippleNotification"
        ripple:rv_color="@color/rippelColor"
        ripple:rv_rippleDuration="200"
        ripple:rv_type="rectangle">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <com.bonafyd.foruser.forImageLoading.ImageViewRounded
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_marginRight="10dp"
                    android:id="@+id/notiAvatar"/>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:layout_gravity="center"
                    android:orientation="vertical">
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Notification"
                        android:textColor="#343434"
                        android:id="@+id/tvNotification" />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Date"
                        android:textSize="12sp"
                        android:id="@+id/tvDate" />
                </LinearLayout>



            </LinearLayout>

        </LinearLayout>
    </com.andexert.library.RippleView>
</RelativeLayout>

自适应

class NotificationAdapter extends BaseAdapter{
    ArrayList<NotificationValues> notificationArrayList;
    public NotificationAdapter(ArrayList<NotificationValues> list)
    {
        notificationArrayList = list;
    }
    @Override
    public int getCount() {
        return notificationArrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return notificationArrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LayoutInflater inflaterPostPanel = getLayoutInflater();
        View row = inflaterPostPanel.inflate(R.layout.notification_list_item, viewGroup, false);
        TextView tvNotification = (TextView) row.findViewById(R.id.tvNotification);
        TextView tvDate = (TextView) row.findViewById(R.id.tvDate);
        RippleView rippleNotification = (RippleView) row.findViewById(R.id.rippleNotification);
        ImageViewRounded notiAvatar = (ImageViewRounded) row.findViewById(R.id.notiAvatar);

        final NotificationValues notificationValues = notificationArrayList.get(i);
        tvNotification.setText(notificationValues.notifText);
        tvDate.setText(dbManager.getTimeStampNew(notificationValues.notifDate));

        Picasso.with(context).load(notificationValues.avatar).resize(90, 90).centerCrop().into(notiAvatar);

        final SharedPreferences pref = context.getSharedPreferences("User", 0);
        rippleNotification.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                }
        });


        return row;
    }
}
class NotificationAdapter扩展了BaseAdapter{
ArrayList notificationArrayList;
公共通知适配器(ArrayList列表)
{
notificationArrayList=列表;
}
@凌驾
public int getCount(){
返回notificationArrayList.size();
}
@凌驾
公共对象getItem(int i){
返回notificationArrayList.get(i);
}
@凌驾
公共长getItemId(int i){
返回0;
}
@凌驾
公共视图getView(int i、视图视图、视图组视图组){
LayoutFlater充气机PostPanel=GetLayoutFlater();
视图行=充气后面板充气(R.layout.notification\u list\u项,视图组,false);
TextView tvNotification=(TextView)row.findViewById(R.id.tvNotification);
TextView-tvDate=(TextView)row.findViewById(R.id.tvDate);
RippleView rippleNotification=(RippleView)row.findViewById(R.id.rippleNotification);
ImageViewRounded notiAvatar=(ImageViewRounded)row.findViewById(R.id.notiAvatar);
最终NotificationValues NotificationValues=notificationArrayList.get(i);
tvNotification.setText(notificationValues.notifText);
tvDate.setText(dbManager.getTimeStampNew(notificationValues.notifDate));
毕加索.with(context).load(notificationValues.avatar).resize(90,90).centerCrop().into(notiAvatar);
最终SharedReferences pref=context.getSharedReferences(“用户”,0);
rippleNotification.setOnRippleCompleteListener(新的RippleView.OnRippleCompleteListener(){
@凌驾
未完成的公共空白(RippleView RippleView){
}
});
返回行;
}
}
使用此 :


使用视图持有者在listView中绑定视图此问题..这将很有帮助,谢谢大家!是的,只是持有人创造了奇迹!!!!