在列表视图中显示或隐藏对象

时间:2018-04-12 13:17:09

标签: android listview scroll

imageview中的图像从ListView的滚动视图中消失。我怎么解决呢?

    public class IzahAdapter extends BaseAdapter {
    private ArrayList<IzahVeriModeli> list;
    LayoutInflater layoutInflater;
    Context context;
    holder Holder;
    int pos;
    public IzahAdapter(Context context, ArrayList<IzahVeriModeli> list) {
        this.context = context;
        // Layout Inflater tanımlanıyor...
        this.list = list;
    }

    @Override
    public int getCount() {

        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);

    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Holder=null;
        View satirView = null;
        Button bIngg, bTrr;
        ImageView resimm = null;
//
    if (convertView == null) {
        layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.listview_izahat, parent, false);
        Holder = new holder();
        Holder.resim = (ImageView) convertView.findViewById(resim);
        Holder.bIng = (Button) convertView.findViewById(bIng);
        Holder.bTr = (Button) convertView.findViewById(bTr);

        Holder.bTr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pos = (Integer)v.getTag();
                list.get(pos).setSelected(false);
                System.out.println("pip2 = " + Integer.toString(pos));
                notifyDataSetChanged();
            }
        });
        Holder.bIng.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos = (Integer)v.getTag();
                list.get(pos).setSelected(true);
                System.out.println("pip3 = " + Integer.toString(pos));
                notifyDataSetChanged();

            }
        });
        convertView.setTag(Holder);
    }
    else {

        Holder = (holder) convertView.getTag();
    }
        Holder.bTr.setTag(position);
        Holder.bIng.setTag(position);
        Holder.resim.setTag(position);
        System.out.println("pip1 = " + position);

        if (list.get(position).isSelected()) {
            Holder.bTr.setVisibility(View.VISIBLE);
            Holder.bIng.setVisibility(View.GONE);
            notifyDataSetChanged();
        } else {
            Holder.bTr.setVisibility(View.GONE);
            Holder.bIng.setVisibility(View.VISIBLE);
            notifyDataSetChanged();
        }
        if (this.list.get(position).getResim()!=null)
        {
            Holder.resim.setImageBitmap(this.list.get(position).getResim2());
        }
        else
        {
            Holder.resim.getLayoutParams().width=0;
        }

        return convertView;
    }
}    

Imageview中的图像来自数据库。如果它是null,ImageView会缩小,如果没有它会添加图像,但是当我滚动列表视图时,事情会变得混乱。

我做了很多努力,但我没有得到解决。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="@drawable/satir_arkaplan"
android:orientation="horizontal"

android:padding="0dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:padding="5dp">

    <ImageView
        android:id="@+id/resim"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical" />

</LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:baselineAligned="false"
    android:gravity="center_horizontal|center"
    android:orientation="vertical"
    android:padding="5dp">

    <Button
        android:id="@+id/bIng"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/ing"
        android:textSize="9dp"
        android:layout_weight="1"/>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal|center"
    android:layout_weight="1"
    android:gravity="center_horizontal"
    android:orientation="horizontal"
    android:padding="5dp">

    <Button
        android:id="@+id/bTr"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal|center"
        android:background="@drawable/turk"
        android:textSize="10dp" />

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

尝试类似的东西:

  if (this.list.get(position).getResim()!=null) {

            Holder.resim.setVisibility(View.Visible);                
            Holder.resim.setImageBitmap(this.list.get(position).getResim2());
        }
        else {
            Holder.resim.setVisibility(View.Gone);
            Holder.resim.setImageresource(0);
        }