title: Xamarin.Forms ListView duplicate items on Android
body: <p>When I run the app on Android, only the first few items in the ListView are displayed correctly, every item after that is a duplicate of one of the first shown items on the list. This is only an UI and not a logic problem, because when I select an item from the list, the SelectedItem is set to the correct item from the list.</p>
  
  <p>Also, the color is correct only on the first card, the colors on the other cards are not the correct colors for the corresponding item.</p>
  
  <p><strong>The app runs perfectly on UWP, this issue is only on Android.</strong> My guess is that it has something to do with the ListView Caching Strategy (RetainElement, RecycleElement or RecycleElementAndDataTemplate). I have tried making custom ListView controls and setting the different Caching Strategies, but no luck so far.</p>
  
  <p><a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance</a></p>
  
  <p><a href="https://i.stack.imgur.com/bG6nR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bG6nR.png" alt="Android vs UWP"></a></p>
  
  <p><em>This is the ListView in XAML:</em></p>
  
  <pre><code>&lt;ListView 
  SelectedItem="{Binding SelectedItem}"
  ItemsSource="{Binding Cards}"
  HasUnevenRows="True"&gt;
      &lt;ListView.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;ViewCell&gt;
                  &lt;StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="5, 2.5"
                               BackgroundColor="{Binding CardColor.Pale}"&gt;
                      &lt;BoxView HeightRequest="10" BackgroundColor="{Binding CardColor.Bright}"/&gt;
                      &lt;StackLayout Padding="10, 2.5, 10, 10"&gt;
                          &lt;Label Text="Date" FontSize="10"/&gt;
                          &lt;Label Text="{Binding Title}"/&gt;
                          &lt;Label Text="{Binding Text}"/&gt;
                      &lt;/StackLayout&gt;
                  &lt;/StackLayout&gt;
              &lt;/ViewCell&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListView.ItemTemplate&gt;
  &lt;/ListView&gt;
  </code></pre>
  
  <p><em>Card.cs</em></p>
  
  <pre><code>public class Card : MvxNotifyPropertyChanged
  {
      private int _id;
      private string _title;
      private string _text;
      private CardColor _cardColor;
  
      public int Id { get =&gt; _id; set =&gt; SetProperty(ref _id, value); }
      public string Title { get =&gt; _title; set =&gt; SetProperty(ref _title, value); }
      public string Text { get =&gt; _text; set =&gt; SetProperty(ref _text, value); }
      public CardColor CardColor { get =&gt; _cardColor; set =&gt; SetProperty(ref _cardColor, value); }
  
      public Card(int id, string title, string text, CardColor cardColor)
      {
          Id = id;
          Title = title;
          Text = text;
          CardColor = cardColor;
      }
  }
  </code></pre>
  
  <p><em>CardColor.cs</em></p>
  
  <pre><code>public class CardColor
  {
      public Color Bright { get; set; }
      public Color Pale { get; set; }
  
      public CardColor(Color bright, Color pale)
      {
          Bright = bright;
          Pale = pale;
      }
  }
  </code></pre>