Android insert button into a LinearLayout at Runtime
<p>I have a linear Layout defined within my xml file as follows</p>

<pre><code>   &lt;LinearLayout
        android:id="@+id/manageStoresAlphabeticPagination"
        android:layout_width="fill_parent"
        android:orientation="horizontal"
        android:weightSum="26"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/searchBarFrameManageStores"
        android:layout_toRightOf="@+id/searchBarFrameManageStores" &gt;

        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="A"
            android:layout_weight="1"
            style="@style/alphaPaginationStyle" /&gt;
        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="B"
            android:layout_weight="1"
            style="@style/alphaPaginationStyle" /&gt;
        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="C"
            android:layout_weight="1"
            style="@style/alphaPaginationStyle" /&gt;
    &lt;/LinearLayout&gt;
</code></pre>

<p>Now that content of the lineaar layout will contain all the alphabets. I dont want to define them in my layout rather through my code. How can create the button through my code, apply the style and then add it to the linear layout ? </p>

<p>Kind Regard</p>

<p>----------------EDIT--------------------------------</p>

<pre><code>LinearLayout storePaginationLayout = (LinearLayout) view
                .findViewById(R.id.manageStoresAlphabeticPagination);

        for (int i = 0; i &lt; 22; i++) {
            Button b1 = new Button(this.getActivity(), null,
                    R.style.alphaPaginationStyle);
            b1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT,1f));
            b1.setText("A");
            storePaginationLayout.addView(b1);
        }
</code></pre>

<p>The styles is not been applied from the code. However from the xml layout it works fine ? </p>
