title: Android Listview: Dynamically adding images in BaseAdapter:getView cause duplicate images
body: <p>I'm extending the BaseAdapter class in my listview adapter class. In this class, I dynamically add images in each row. But for some reason, I got duplicate number of images inside a row.</p>
  
  <p>I tried logging while dynamically adding images in the getView and it appears that the getView was called twice. How can I fix this?</p>
  
  <p>This is the snippets:</p>
  
  <pre><code>public View getView(int position, View convertView, ViewGroup parent) {
          View vi = convertView;
          if(convertView == null){
              vi = inflater.inflate(R.layout.myrowlayout, null);
          }
  
          HorizontalScrollView horizontalScrollView = (HorizontalScrollView)vi.findViewById(R.id.horizontallayout);
          LinearLayout imagesLayout = (LinearLayout)vi.findViewById(R.id.linearlayoutinsidehorizontal);
  
  
          LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(...);
          //...
          LinearLayout.LayoutParams ilp = new LinearLayout.LayoutParams(...);
          //...
  
          RowData current = new RowData();
          current = data.get(position);
  
          if(current.hasImage()){
              //...
              ArrayList&lt;String&gt; images = current.getImages();
              for(int i = 0; i &lt; images.size(); i++){
                  ImageView currImage = new ImageView(mActivity);
                  currImage.setLayoutParams(ilp);
                  imagesLayout.addView(currImage);
                  imageLoader.DisplayImage(images.get(i), currImage);
                  //imageLoader is an implementation of [LazyList] see note below
                  Log.d("PostListAdapter:getView", "image[" + i + "]: " + images.get(i));
              }
              horizontalScrollView.removeAllViews();
              horizontalScrollView.addView(imagesLayout);
          }
  
          return vi;
      }
  </code></pre>
  
  <p>From onCreate of the calling Activity:</p>
  
  <pre><code>list = (ListView)findViewById(R.id.listviewfromlayout);
  adapter = new MyAdapter(MyActivty.this, arraylistOfData);
  list.setAdapter(adapter);
  </code></pre>
  
  <p>Note:</p>
  
  <p>I've use the <a href="https://github.com/thest1/LazyList" rel="nofollow">LazyList</a> to load all the images.</p>