Dynamic GridLayout
<p>I made an error in another class, that's why it didn't work. The code below seems to be correct</p>

<p>I'm trying to create a dynamic GridLayout. Inside another class, not this one, I have a method that designs rows and cols of my gridlayout.</p>

<p>In the class below, i add some buttons to my GridLayout</p>

<pre><code> int buttons= 6;//the number of bottons i have to put in GridLayout

 int buttonsForEveryRow = 3; // buttons i can put inside every single row

 int buttonsForEveryRowAlreadyAddedInTheRow =0; // count the buttons added in a single rows

 int columnIndex=0; //cols index to which i add the button

 int rowIndex=0; //row index to which i add the button






            for(int i=0; i &lt; buttons;i++){          

                /*if numeroBottoniPerRigaInseriti equals numeroBottoniPerRiga i have to put the other buttons in a new row*/
                if(buttonsForEveryRowAlreadyAddedInTheRow ==buttonsForEveryRow ){
                    rowIndex++; //here i increase the row index
                    buttonsForEveryRowAlreadyAddedInTheRow  =0;  
                    columnIndex=0; 
                }       


                Spec row = GridLayout.spec(rowIndex, 1); 
                Spec colspan = GridLayout.spec(columnIndex, 1);
                GridLayout.LayoutParams gridLayoutParam = new GridLayout.LayoutParams(row, colspan);
                gridLayout.addView(button_to_add,gridLayoutParam);



                buttonsForEveryRowAlreadyAddedInTheRow ++;
                columnIndex++;
</code></pre>

<p>In this image you can see what i get; there arent' the buttons 3 and 6. I'm afraid i'm not using properly  <code>GridLayout.spec</code></p>

<p><img src="http://i.stack.imgur.com/f8USq.png" alt="enter image description here"></p>
