title: How to add multiple custom linearLayouts programmatically to listView item
body: <p>I've got a quite irritating problem. My task is to add multiple LinearLayouts with custom XML template (And I don't know how many of Layouts there could be) with 2 TextViews inside (in each) into 1 ListView item.
  Like this:<img src="https://i.stack.imgur.com/QYKtm.png" alt="enter image description here"></p>
  
  <p>Is it possible to do this in ArrayAdapter? Any help would be much appreciated!</p>
  
  <p>Ok, i've managed to did something with help from Jonas Cz.
  And this is what I've got.</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      if(convertView == null)
      {
          convertView = inflater.inflate(R.layout.parsed_csv_list_view_main_item, parent, false);
      }
      RealmResults&lt;ParsedCSV&gt; titles = parentFragment.getParsedCSVtitles();
      String[] parsedTitles = titles.get(0).getValues().split(";");
      String[] parsedValues = items.get(position).getValues().split(";");
  
      for (int i = 0; i &lt; parsedValues.length; i++) {
          View holder = inflater.inflate(R.layout.parsed_csv_list_view_subitem, parent, false);
          TextView textViewTitles = (TextView) holder.findViewById(R.id.parsed_csv_list_view_subitem_text_title);
          TextView textViewValues = (TextView) holder.findViewById(R.id.parsed_csv_list_view_subitem_text_value);
          textViewTitles.setText(parsedTitles[i]);
          textViewValues.setText(parsedValues[i]);
          ((LinearLayout) convertView).addView(holder);
      }
      return ((View)convertView);
  }
  </code></pre>
  
  <p>I had to cast my convertView to LinearLayout because just converView didn't had addView method. Ok, it's a shit but it works...with some problem.
  Now, while scrolling, it seems like the amount of items in list increases for some reason. Can someone explain me why is this happening and how to fix it?</p>
  
  <p><strong>FULLY WORKING SOLUTION FROM</strong> JonasCz:</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      if(convertView == null)
      {
          convertView = inflater.inflate(R.layout.parsed_csv_list_view_main_item, parent, false);
  
      } else {
          ((LinearLayout) convertView).removeAllViews();
      }
      RealmResults&lt;ParsedCSV&gt; titles = parentFragment.getParsedCSVtitles();
      String[] parsedTitles = titles.get(0).getValues().split(";");
      String[] parsedValues = items.get(position).getValues().split(";");
  
      for (int i = 0; i &lt; parsedValues.length; i++) {
         View holder = inflater.inflate(R.layout.parsed_csv_list_view_subitem, parent, false);
         TextView textViewTitles = (TextView) holder.findViewById(R.id.parsed_csv_list_view_subitem_text_title);
         TextView textViewValues = (TextView) holder.findViewById(R.id.parsed_csv_list_view_subitem_text_value);
         textViewTitles.setText(parsedTitles[i]);
         textViewValues.setText(parsedValues[i]);
         ((LinearLayout) convertView).addView(holder);
       }
      return ((View)convertView);
     }
  </code></pre>