title: Rows being repeated in ListView
body: <p>I know this question has appeared a number of times but for some reason I can't seem to get it to work.
  The fact that getView is called multiple times in certain cases.</p>
  
  <p>However, in the example given here: <a href="http://android.amberfog.com/?p=296" rel="nofollow noreferrer">http://android.amberfog.com/?p=296</a>
  it says that the first call for each row in the data should get a null value in currentView.
  This is not happening.</p>
  
  <p>What is happening for me is that the calls when position is 0 has currentView set to null whereas the calls where position is 1 has currentView set to an existing object.</p>
  
  <p>In total 16 calls are made to "getView" but I get the rows duplicated once (i.e two of each row).
  Row 0
  Row 1
  Row 0 
  Row 1</p>
  
  <p>I probably just didn't understand something from that post.</p>
  
  <p>Layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"   
      android:layout_height="fill_parent"
      &gt;
      &lt;TextView android:id="@+id/title_paired_devices" 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/title_paired_devices" 
          android:visibility="gone"
          android:background="#666"
          android:textColor="#fff"
          android:paddingLeft="5dp"
      /&gt;
      &lt;ListView android:id="@+id/paired_devices"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:stackFromBottom="true"
          android:layout_weight="1"
      /&gt;
      &lt;TextView android:id="@+id/title_new_devices"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/title_other_devices"
          android:visibility="gone"
          android:background="#666"
          android:textColor="#fff"
          android:paddingLeft="5dp"
      /&gt;
      &lt;ListView android:id="@+id/new_devices"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:stackFromBottom="true"
          android:layout_weight="2"
      /&gt;
      &lt;Button android:id="@+id/button_scan" 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/button_scan"
      /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Listview row:</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="fill_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/list_selector"
      android:orientation="horizontal"
      android:padding="5dip" &gt;
  
      &lt;!--  ListRow Left side Thumbnail image --&gt;
      &lt;LinearLayout android:id="@+id/thumbnail"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="3dip"
          android:layout_alignParentLeft="true"
          android:background="@drawable/image_bg"
          android:layout_marginRight="5dip"&gt;
  
          &lt;ImageView
              android:id="@+id/list_image"
              android:layout_width="50dip"
              android:layout_height="50dip"
              android:src="@drawable/icon"/&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;!-- Device Address --&gt;
      &lt;TextView
          android:id="@+id/tvwDeviceAddress"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignTop="@+id/thumbnail"
          android:layout_toRightOf="@+id/thumbnail"
          android:textColor="#040404"
          android:typeface="sans"
          android:textSize="15dip"
          android:textStyle="bold"/&gt;
  
      &lt;!-- Display Name --&gt;
      &lt;TextView
          android:id="@+id/tvwDisplayName"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/tvwDeviceAddress"
          android:textColor="#343434"
          android:textSize="10dip"
          android:layout_marginTop="1dip"
          android:layout_toRightOf="@+id/thumbnail"/&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Adapter:</p>
  
  <pre><code>    private class LazyAdapter extends BaseAdapter {
  
      private Activity activity;
      private ArrayList&lt;MPGDeviceDetails&gt; data;
      private LayoutInflater inflater=null;
  
      public LazyAdapter(Activity a, ArrayList&lt;MPGDeviceDetails&gt; d) {
          activity = a;
          data=d;
          inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      public int getCount() {
          return data.size();
      }
  
      public Object getItem(int position) {
          return position;
      }
  
      public long getItemId(int position) {
          return position;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          View vi=convertView;
          Log.e("MPG","Position = " + position + ".  ConvertView = " + convertView);
          if(convertView==null)
              vi = inflater.inflate(R.layout.device_name, null);
  
          TextView address = (TextView)vi.findViewById(R.id.tvwDeviceAddress); // Device Address
          TextView name = (TextView)vi.findViewById(R.id.tvwDisplayName); // Display name
          ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
  
  
  
          address.setText(data.get(position).deviceAddress);
          name.setText(data.get(position).getDisplayName());
          Bitmap photo = data.get(position).getContactPhoto();
          if (photo != null)
              thumb_image.setImageBitmap(photo);
  
  
          return vi;
      }
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      // Setup the window
      requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
      setContentView(R.layout.device_list);
  
      // Set result CANCELED incase the user backs out
      setResult(Activity.RESULT_CANCELED);
  
      // Initialize the button to perform device discovery
      Button scanButton = (Button) findViewById(R.id.button_scan);
      scanButton.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
              doDiscovery();
              v.setVisibility(View.GONE);
          }
      });
  
      // Initialize array adapters. One for already paired devices and
      // one for newly discovered devices
  
  
      // Find and set up the ListView for paired devices
      pairedListView = (ListView) findViewById(R.id.paired_devices);
      pairedDevicesList = new ArrayList&lt;MPGDeviceDetails&gt;();
      pairedListView.setAdapter((mPairedDevicesArrayAdapter = new LazyAdapter(this,pairedDevicesList)));
      pairedListView.setOnItemClickListener(mDeviceClickListener);
      registerForContextMenu(pairedListView);
  
      // Get the local Bluetooth adapter
      mBtAdapter = BluetoothAdapter.getDefaultAdapter();
  
      // Get a set of currently paired devices
      Set&lt;BluetoothDevice&gt; pairedDevices = mBtAdapter.getBondedDevices();
  
      // If there are paired devices, add each one to the ArrayAdapter
      if (pairedDevices.size() &gt; 0) {
          findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
          for (BluetoothDevice device : pairedDevices) {
            pairedDevicesList.add(MPGDeviceDetailsControl.getDeviceDetails(this, device.getAddress(), device.getName()));
          }
      } 
  
  }
  </code></pre>
  
  <p>MPGDeviceDetails is an object that holds all the data about a specific device.</p>
  
  <p>This is the output from the "debug" command:</p>
  
  <pre><code>03-27 10:03:30.730: E/MPG(2841): Position = 0.  ConvertView = null.
  03-27 10:03:30.742: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@4062d608. 
  03-27 10:03:30.746: E/MPG(2841): Position = 0.  ConvertView = null. 
  03-27 10:03:30.750: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@40628d78. 
  03-27 10:03:30.750: E/MPG(2841): Position = 0.  ConvertView = android.widget.RelativeLayout@4062d608. 
  03-27 10:03:30.753: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@4062d608. 
  03-27 10:03:30.753: E/MPG(2841): Position = 0.  ConvertView = android.widget.RelativeLayout@40628d78. 
  03-27 10:03:30.753: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@40628d78. 
  03-27 10:03:30.761: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@4062d608. 
  03-27 10:03:30.761: E/MPG(2841): Position = 0.  ConvertView = null. 
  03-27 10:03:30.769: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@40628d78. 
  03-27 10:03:30.769: E/MPG(2841): Position = 0.  ConvertView = null. 
  03-27 10:03:30.777: E/MPG(2841): Position = 0.  ConvertView = null. 
  03-27 10:03:30.781: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@406d4af8. 
  03-27 10:03:30.781: E/MPG(2841): Position = 0.  ConvertView = null. 
  03-27 10:03:30.785: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@40694970. 
  03-27 10:03:30.789: E/MPG(2841): Position = 0.  ConvertView = android.widget.RelativeLayout@406d4af8. 
  03-27 10:03:30.789: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@406d4af8. 
  03-27 10:03:30.789: E/MPG(2841): Position = 0.  ConvertView = android.widget.RelativeLayout@40694970. 
  03-27 10:03:30.792: E/MPG(2841): Position = 1.  ConvertView = android.widget.RelativeLayout@40694970. 
  </code></pre>
  
  <p>This is what the screen looks like:
  <img src="https://i.stack.imgur.com/xYqUi.png" alt="enter image description here"></p>
  
  <p>Funny thing is that, whilst all 4 buttons work, the context-menu only works for the first two!</p>