title: Item missing from android grid view on scroll
body: <p>I have grid view , on which each item consists of few images and text . When it loads for the first time , everything is fine but if I scroll to the bottom and the go back to top some two images are gone from a item , and it goes randomly . </p>
  
  <p>here is the code for Grid view </p>
  
  <pre><code>  &lt;GridView
          android:id="@+id/testR_grid"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="5dp"
          android:layout_marginRight="5dp"
          android:clickable="true"
          android:columnWidth="@dimen/gridview_column_width"
          android:horizontalSpacing="@dimen/grid_horizontal_spacing"
          android:listSelector="@drawable/gridview_background"
          android:numColumns="auto_fit"
          android:scrollbarStyle="outsideOverlay"
          android:scrollbars="vertical"
          android:verticalScrollbarPosition="right"
          android:verticalSpacing="@dimen/grid_vertical_spacing"
          android:fastScrollEnabled="false"/&gt;
  </code></pre>
  
  <p>Here the code for single item </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="250dp"
      android:layout_marginTop="5dp"
      android:descendantFocusability="blocksDescendants"
      android:orientation="vertical"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@drawable/blurry_shadow_rect"&gt;
  
          &lt;com.joooonho.SelectableRoundedImageView xmlns:app="http://schemas.android.com/apk/res-auto"
              android:id="@+id/item_image"
              android:layout_width="match_parent"
              android:layout_height="@dimen/gridview_column_width"
              android:layout_alignParentTop="true"
              android:layout_centerHorizontal="true"
              android:layout_marginBottom="5dp"
              android:layout_marginTop="-5dp"
  
              app:sriv_left_bottom_corner_radius="0dip"
              app:sriv_left_top_corner_radius="4dip"
              app:sriv_right_bottom_corner_radius="0dip"
              app:sriv_right_top_corner_radius="4dip" /&gt;
  
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_below="@+id/item_image"
              android:layout_marginBottom="5dp"
              android:layout_marginLeft="2dp"
              android:orientation="horizontal"
              android:weightSum="100"&gt;
  
              &lt;RelativeLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_weight="35"&gt;
  
                  &lt;TextView
                      android:id="@+id/item_text"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:layout_alignParentLeft="true"
                      android:layout_gravity="start"
                      android:layout_marginBottom="5dp"
                      android:ellipsize="end"
                      android:fontFamily="sans-serif-light"
                      android:maxLines="1"
                      android:text=""
                      android:textColor="@color/bodyText"
                      android:textSize="@dimen/GridHeader" /&gt;
  
                  &lt;TextView
                      android:id="@+id/item_TestA_name"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:layout_alignParentLeft="true"
                      android:layout_below="@+id/item_text"
                      android:layout_marginBottom="10dp"
                      android:alpha=".5"
                      android:ellipsize="end"
                      android:maxLines="1"
                      android:text=""
                      android:textColor="@color/bodyText"
                      android:textSize="@dimen/GridHeader2" /&gt;
              &lt;/RelativeLayout&gt;
  
              &lt;RelativeLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginRight="2dp"
                  android:layout_weight="65"&gt;
  
                  &lt;TextView
                      android:id="@+id/item_testR_free_text"
                      style="@style/textview_grid_free_banner"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignParentRight="true"
                      android:layout_alignParentTop="true"
                      android:fontFamily="sans-serif-light"
                      android:maxLines="1"
                      android:padding="2dp"
                      android:singleLine="true"
                      android:text=" FREE " /&gt;
  
  
                  &lt;ImageView
                      android:layout_width="20dp"
                      android:layout_height="20dp"
                      android:id="@+id/already_owned"
                      android:layout_centerVertical="true"
                      android:layout_alignParentRight="true"
                      android:layout_alignParentTop="true"
                      android:singleLine="true"
                      android:layout_marginLeft="20dp"
                      android:layout_marginBottom="5dp"
                      android:visibility="gone"
                      android:layout_marginEnd="10dp"
                      android:layout_marginRight="10dp"
                      android:src="@drawable/ic_testR_bought_36dp" /&gt;
  
                  &lt;ImageButton
                      android:id="@+id/item_testR_more_options"
                      android:layout_width="@dimen/image_button_more"
                      android:layout_height="@dimen/image_button_more"
                      android:layout_alignParentEnd="true"
                      android:layout_alignParentRight="true"
                      android:layout_below="@+id/item_testR_free_text"
                      android:alpha=".5"
                      android:background="@drawable/imagebutton_background"
                      android:clickable="true"
                      android:focusable="false"
  
                      android:src="@drawable/ic_more_vert_black_24dp" /&gt;
              &lt;/RelativeLayout&gt;
          &lt;/LinearLayout&gt;
  
      &lt;/RelativeLayout&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>The elements are randomly missing  are text view which id is <code>item_testR_free_text</code> and imageview which id <code>is already_owned</code> . One thing also to be noted the visibility of these two items are conditional .</p>
  
  <p>Here is my code for adapter</p>
  
  <pre><code>public class TestRGridViewAdapter extends ArrayAdapter&lt;TestR&gt; {
      Context context;
      int layoutResourceId;
      List&lt;TestR&gt; data = new ArrayList&lt;TestR&gt;();
      RecordHolder holder = null;
      //DiskCache imgCache;
      TestA TestA;
      TestR item;
      FragmentActivity mFragmentActivity;
      boolean is_local = false;
      List&lt;Track&gt; trackList;
  
      public TestR getItem() {
          return item;
      }
  
      public void setItem(TestR item) {
          this.item = item;
      }
  
      public TestRGridViewAdapter(Context context, int layoutResourceId,
                                    List&lt;TestR&gt; data, FragmentActivity mFragmentActivity, boolean is_local) {
          super(context, layoutResourceId, data);
          this.layoutResourceId = layoutResourceId;
          this.context = context;
          this.data = data;
          this.mFragmentActivity = mFragmentActivity;
  //        imgCache = Parameters.imgCache;
          this.is_local = is_local;
      }
  
      public TestRGridViewAdapter(Context context, int layoutResourceId,
                                    List&lt;TestR&gt; data, FragmentActivity mFragmentActivity) {
          super(context, layoutResourceId, data);
          this.layoutResourceId = layoutResourceId;
          this.context = context;
          this.data = data;
          this.mFragmentActivity = mFragmentActivity;
      }
  
  
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row = convertView;
          if (row == null) {
              //LayoutInflater inflater = ((Activity) context).getLayoutInflater();
              row = LayoutInflater.from(context).inflate(layoutResourceId, null);
              //row = inflater.inflate(layoutResourceId, parent, false);
              holder = new RecordHolder();
              holder.item_testR_free_text = (TextView) row.findViewById(R.id.item_testR_free_text);
              holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
              holder.txtTestAName = (TextView) row.findViewById(R.id.item_TestA_name);
              holder.imageItem = (SelectableRoundedImageView) row.findViewById(R.id.item_image);
              holder.item_testR_more_options = (ImageButton) row.findViewById(R.id.item_testR_more_options);
              holder.already_owned = (ImageView) row.findViewById(R.id.already_owned);
  //            holder.grid_swipe_refresh_layout = (SwipeRefreshLayout) row.findViewById(R.id.grid_swipe_refresh_layout);
  
              row.setTag(holder);
          } else {
              holder = (RecordHolder) row.getTag();
          }
          item = data.get(position);
  
          holder.txtTitle.setText(item.getName());
  
  //        else
  //            holder.txtArtitName.setText("");
          //holder.imageItem.setImageBitmap(item.getImage());
          try {
              if (item.getTestA_id() == null)
                  item = new SaveData(context).get_online_testR(item.getTestR_id());
              TestA = Helper.getDaoSession(context).getTestADao().load(item.getTestA_id());
              if (TestA == null) {
                  TestA = new SaveData(context).get_save_TestA(item.getTestA_id());
              }
  //            if (TestA != null)
              holder.txtTestAName.setText((TestA != null) ? TestA.getName() : "");
  //            else
  //                TestA = new SaveData(context).get_save_TestA(item.getTestA_id());
  
  
              if (!is_local) {
  
                  if(!DBQuery.is_owner(context,item.getTestR_id())) {
  
                      Log.d("test","not owner - "+item.getName());
  
                      holder.item_testR_free_text.setText(
                              UXHelper.getPriceFromString(Parameters.price_type.equals("local_price") ?
                                      item.getLocal_price().toString() : item.getPrice().toString()));
                      holder.already_owned.setVisibility(View.INVISIBLE);
  
                      holder.item_testR_more_options.setOnClickListener(new testR_popup_onClick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA));
                  }else {
                      Log.d("test","owner - "+item.getName());
                      holder.item_testR_free_text.setVisibility(View.INVISIBLE);
                      holder.already_owned.setVisibility(View.VISIBLE);
                      holder.item_testR_more_options.setOnClickListener(new testR_popup_onClick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA));
                  }
  
              } else {
                  Log.d("test","local - "+item.getName());
                  holder.already_owned.setVisibility(View.INVISIBLE);
                  boolean synced = true;
  
                  trackList = new ArrayList&lt;Track&gt;();
                  List&lt;Track&gt; trackListTmp = new SaveData(context).get_tracks_local(item.getTestR_id());
                  boolean testR_owner = DBQuery.is_owner(context, trackListTmp.get(0).getTestR_id());
                  for (Track t : trackListTmp) {
                      boolean track_owner = DBQuery.is_owner(context, t.getTrack_id(), t.getTestR_id());
                      if (track_owner)
                          trackList.add(t);
                      if (testR_owner || track_owner) {
                          if (t.getSynced_dir() == null) {
                              synced = false;
  //                        break;
                          } else if (!new File(t.getSynced_dir()).exists()) {
                              synced = false;
  //                        break;
                          }
                      }
  
                  }
  
                  if (synced) {
                      Log.d("test","synched - "+item.getName());
                      holder.item_testR_free_text.setVisibility(View.VISIBLE);
                      holder.item_testR_free_text.setText("Synced");
                  } else {
                      Log.d("test","not synched - "+item.getName());
                      holder.item_testR_free_text.setVisibility(View.INVISIBLE);
                      holder.item_testR_more_options.setOnClickListener(
                              new testR_popup_downloaded_onCLick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA,
                                      trackList.toArray(new Track[trackList.size()]), synced));
                  }
              }
              Target target = new Target() {
                  @Override
                  public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                      holder.imageItem.setImageBitmap(bitmap);
                  }
  
                  @Override
                  public void onBitmapFailed(Drawable errorDrawable) {
                      holder.imageItem.setImageResource(R.drawable.ic_example_36);
                  }
  
                  @Override
                  public void onPrepareLoad(Drawable placeHolderDrawable) {
                      holder.imageItem.setImageResource(R.drawable.ic_example_36);
                  }
              };
  
  
              if (Parameters.mPicasso == null)
                  Parameters.mPicasso = new Picasso.Builder(context)
  
                          .build();
  
              Parameters.mPicasso.load("http://" + context.getString(R.string.ip) + "/" +
                      context.getString(R.string.TestRsController) + "/" + context.getString(R.string.TESTR_THUMB_URL)
                      + "/" + item.getTestR_id()+"/"+Parameters.dpi)
  
  
                      .placeholder(R.drawable.ic_example_36)
                      .error(R.drawable.ic_example_36)
  
                      .into(holder.imageItem);
  
          } catch (Exception ex) {
              new Logger(context).appendLog("Error in TestR grid view item " + ex.getMessage());
          }
          return row;
  
      }
  
      static class RecordHolder {
          //        SwipeRefreshLayout grid_swipe_refresh_layout;
          TextView txtTitle;
          TextView txtTestAName;
          SelectableRoundedImageView imageItem;
          TextView item_testR_free_text;
          ImageButton item_testR_more_options;
          ImageView already_owned;
      }
  }
  </code></pre>