0
メインアクティビティのボタンをクリックすると、垂直スクロール内に垂直線形レイアウトを動的に作成する必要があります。線形レイアウトには、主アクティビティーの編集テキストに示されている行数と同じ数の行がなければなりません。Android:可変要素を持つフラグメントを作成する
ボタンを押したときに線形レイアウトとスクロールを使用してフラグメントを作成する方法を説明しましたが、主なアクティビティの編集テキストの値に応じてこの線形レイアウトをボタンで埋める方法がわかりません。
グラフィカル説明:
私はこのコードを持っている:
public void onAdd(View view) { // This is the method called when button is clicked
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
BlankFragment fragment = new BlankFragment();
transaction.add(R.id.table2,fragment);
transaction.commit();
}
をそして、これはフラグメントのXMLコードです:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.xxxxx.yyyyy.BlankFragment">
<ScrollView
android:id="@+id/sv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/ll6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Buttons go here -->
</LinearLayout>
</ScrollView>
ありがとうございました!! – Sergio
ListViewまたはRecyclerViewで可能です。 LinearLayoutはカスタムアダプタでリストを実装するのに必要なレイアウトのフォーマットです – androidXP