title: Android add multiple fragments to grid layout
body: <p>My application loads multiple articles from a database and shows them as some kind of fragment inside a grid view. My problem is to display every fragment loaded inside this grid view. With my current implementation its limited to just one fragment (always the last one added). I think its because the row and column in which the fragment should be added are defined nowhere. </p>
  
  <p>Is there a way to define row and column in this case or at the best populate the grid automatically? I'm stuck here since a while now and couldn't find a solution yet. </p>
  
  <p>Method to load fragments into grid:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>   private void loadFragmentsFromArticleList(List&lt;DatabaseArticle&gt; articles){
          FragmentTransaction fragmentTransaction;
          grid.removeAllViews();
          for(DatabaseArticle a : articles){
              fragmentTransaction = fragmentManager.beginTransaction();
              CategoryButtonFragment fragment = CategoryButtonFragment.newInstance(a.getName(),"");
              fragmentTransaction.add(R.id.gridButtons,fragment,null).commit();
          }
  
  
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Grid XML</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;GridLayout
                  android:id="@+id/gridButtons"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_above="@+id/btnDB"
                  android:layout_alignParentEnd="true"
                  android:layout_alignParentRight="true"
                  android:layout_below="@+id/btnSearch"
                  android:columnCount="3"
                  android:orientation="horizontal"
                  android:animateLayoutChanges="true"
                  &gt;
  
              &lt;/GridLayout&gt;</code></pre>
  </div>
  </div>
  </p>