title: Android Gridview - Element position changing Randomly when scrolling
body: <p>I have a <code>GridView</code> which have 10 rows and 7 columns. The elements in the <code>GridView</code> are not in a unique form that is one row contains 7 element, one row has only 4 or 5 elements, etc. Now I have created the <code>GridView</code> with full elements that is 70 elements. Now I want to hide some elements in the <code>GridView</code>. I have tried by setting visibility of the <code>ImageView</code> and <code>TextView</code> to <code>View.INVISIBLE</code>. It works but when we scroll the <code>GridView</code> it randomly changes. </p>
  
  <ol>
  <li><p><a href="https://plus.google.com/photos/103076464130813961822/albums/5875103733171068625/5875103737979749602?hl=en&amp;utm_source=lmnavbr&amp;utm_medium=embd&amp;utm_campaign=lrnmre&amp;rtsl=1" rel="nofollow">This is exactly what I wanted</a></p></li>
  <li><p>One more problem is that each row contains a title not to each element.</p></li>
  </ol>
  
  <p>What I have to do? I am new to Android. </p>
  
  <p>Code:</p>
  
  <pre><code>@Override
  public int getCount() 
  {
      // TODO Auto-generated method stub
      return listFlag.size();
  }
  
  @Override
  public String getItem(int position)
  {
      // TODO Auto-generated method stub
      return listCountry.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
  }
  
  public static class ViewHolder
  {
      public ImageView imgViewFlag;
      public TextView txtViewTitle;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      ViewHolder view;
      LayoutInflater inflator = activity.getLayoutInflater();
      int childSize = parent.getChildCount();
      if(convertView==null)
      {
          view = new ViewHolder();
          convertView = inflator.inflate(R.layout.gridview_row, null);
          view.txtViewTitle = (TextView) convertView.findViewById(R.id.textView1);
          view.imgViewFlag  = (ImageView) convertView.findViewById(R.id.imageView1);
          convertView.setTag(view);
      }
      else
      {
          view = (ViewHolder) convertView.getTag();
      }
  
      if(position==64||position==57||position==58||position==59||position==50||position==23||position==16||position==17||position==9||position==10||position==12||position==1||position==2||position==8)
      {
          view.txtViewTitle.setVisibility(View.GONE);
          view.imgViewFlag.setVisibility(View.GONE);
      }
  
      view.txtViewTitle.setText(listCountry.get(position));
      view.imgViewFlag.setImageResource(listFlag.get(position));
  
      return convertView;
  }
  
  }
  </code></pre>