フラグメントに問題がありますが、その理由はわかりません。主な活動には2つの断片があります。一方の側(右)には断片の上にスピナーがあり、その断片にはどの断片がスピナーと置き換えられます。左側には、アレイアダプタを使用してデータを表示したリストビューが表示されています。フラグメントを置換すると別のフラグメントが削除されます
問題は、左側のフラグメントを置き換えるときはいつも、右側のフラグメントが消えて、なぜそれがそれをしているのかわかりません。
これは、左側フラグメントを交換する私のスピナーのコードされています。右側の断片は配列リストに新規追加されたデータを表示するには、次のスピナーにあるボタンを使用してリフレッシュ取得し、それが
personSelection.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
personType = "Student";
StudentFragment studentFrag = StudentFragment.newInstance();
getFragmentManager().beginTransaction()
.replace(R.id.form, studentFrag)
.commit();
} else if (position == 1) {
personType = "Teacher";
TeacherFragment teacherFrag = TeacherFragment.newInstance();
getFragmentManager().beginTransaction()
.replace(R.id.form, teacherFrag)
.commit();
} else if (position == 2) {
personType = "Administrator";
AdminFragment adminFrag = AdminFragment.newInstance();
getFragmentManager().beginTransaction()
.replace(R.id.form, adminFrag)
.commit();
} // end if/else
} // end personSelection
@Override
public void onNothingSelected(AdapterView<?> parent) {}
}); // end selection
ですフラグメントが使用された時間だけです。
私は何を意味するのかを視覚的に示します。
- をスピナーを選択した後:(更新ボタンは、この後のいずれでも動作しません)
-
これは、主な活動のためのXMLです:
<LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <Spinner android:layout_height="40dp" android:id="@+id/person_spinner" android:entries="@array/child" android:layout_width="170dp" /> <Button android:text="Button" android:id="@+id/refresh_button" android:drawableStart="@android:drawable/stat_notify_sync" android:drawableTint="#000000" android:layout_width="45dp" android:layout_height="50dp" /> </LinearLayout> <fragment android:name="com....StudentFragment" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".4" android:id="@+id/form" tools:layout="@layout/student_fragment" /> </LinearLayout> <fragment android:name="com....DetailFragment" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight=".7" android:id="@+id/frame_detail" tools:layout="@layout/fragment_detail"/>