0

私の 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"
    />

4

2 に答える 2

0

気にしないで、私はそれを理解しました。メソッドを使用getSupportFragmentManager().findFragmentById(R.id.frag);してフラグメントへの 4 つの参照を作成し、フラグメントupdateVals()のビューからのデータを Java クラスの変数に格納するメソッドを使用しました。

于 2013-04-01T02:37:45.403 に答える