jjcool
jjcool

Reputation: 61

Disappearing ImageView after scroll in GetView

I have a problem. I have an inflate ListView with icons and texts. All items should have icons (ImageView) (with text1...text5) but last item should haven't an icon (text6). First image is OK, second too, but when I scroll up list (image 3) the icon with text1 disappear. Again when I scroll down list (image 4) the icon with text5 disappear...

enter image description here

   public class MyAdapter extends BaseAdapter {
/*
*/
    public View getView(final int position, View view, ViewGroup parent) {
            final ViewHolder holder;


        if (view == null) {
            view = layoutInflater.inflate(R.layout.list, null);

            holder = new ViewHolder();

            holder.textView1 = (TextView) view.findViewById(R.id.text_view);
            holder.imageView1 = (ImageView) view.findViewById(R.id.icon);

            view.setTag(holder);

        } else {
            holder = (ViewHolder) view.getTag();
        }

/*

*/
     //icons (text1 to text5)
     if (array[position].isTrue()){
        holder.imageView1.setImageResource(R.drawable.icon1);
     }
     else if (!array[position].isTrue()){
        holder.imageView1.setImageResource(R.drawable.icon2);
     }
/* 

*/
    //last item is always equal -1 (text6)
    if (array[position].getId == -1){
        holder.imageView1.setVisibility(View.GONE);
    }

Upvotes: 0

Views: 638

Answers (1)

Mohd Mufiz
Mohd Mufiz

Reputation: 2236

 if (array[position].getId == -1){
        holder.imageView1.setVisibility(View.GONE);
    }
 else
   {
        holder.imageView1.setVisibility(View.VISIBLE);
   }

Upvotes: 1

Related Questions