私の Android アプリには、4 つのフラグメントを持つアクティビティがあります。すべてのフラグメントはまったく同じフィールドを持っているため、すべて同じ xml ファイルからインフレートされ、同じ Java クラスを持っています。ただし、ユーザーはそれぞれにデータを入力するため、それぞれにデータを保存する必要があります。では、それらがすべて同じクラスである場合、どうすればデータを取得できるでしょうか?
activity_success.xml
<Button
android:id="@+id/continue_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cont"
/>
<Button
android:id="@+id/export_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/export"
android:layout_toRightOf="@id/continue_button"
/>
<fragment android:name="org.bah.bu.SuccessFragment"
android:id="@+id/red1_success"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/continue_button"
/>
<fragment android:name="org.bah.bu.SuccessFragment"
android:id="@+id/red2_success"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/red1_success"
/>
fragment_success.xml
<CheckBox
android:id="@+id/far"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/far"
/>
<CheckBox
android:id="@+id/lifted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lifted"
/>