次のように、xml ファイル内で線形レイアウトを定義しています。
<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" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:layout_weight="1"
style="@style/alphaPaginationStyle" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
android:layout_weight="1"
style="@style/alphaPaginationStyle" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:layout_weight="1"
style="@style/alphaPaginationStyle" />
</LinearLayout>
これで、線形レイアウトのコンテンツにすべてのアルファベットが含まれるようになりました。コードではなく、レイアウトでそれらを定義したくありません。コードを使用してボタンを作成し、スタイルを適用してから線形レイアウトに追加するにはどうすればよいですか?
敬具
- - - - - - - - 編集 - - - - - - - - - - - - - - - -
LinearLayout storePaginationLayout = (LinearLayout) view
.findViewById(R.id.manageStoresAlphabeticPagination);
for (int i = 0; i < 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);
}
スタイルはコードから適用されていません。ただし、xml レイアウトからは正常に動作しますか?