2

私は現在3つのタブを持っています。スワイプまたはタブを押すことによる選択の各タブは、XML レイアウトを膨張させるフラグメントをロードします。また、fragmentPagerAdapter と共にビューページャーを使用しています。

タブの1つ(および将来の残り)で、フラグメントのボタンをクリックし、現在のタブの現在のフラグメントを新しいタブに置き換えることができるようにしたいと考えています。途中まで進んだ時点で、ボタンに新しいタブが表示されますが、古いタブの上にあり、新しいフラグメントを呼び出して操作する古いボタンと、上のボタンがまだ表示されています新しいタブ。

フラグメントが適切に置き換えられるようにするにはどうすればよいですか? また、古いフラグメントがバックスタックに配置されているので、タブで戻ることができますか?

これがフラグメントを変更するための私のコードです

public class CreateWorkoutFragment extends Fragment {

    private Button addExerciseButton;
    private FragmentNavigationHelper fragmentNavigationHelper;
    static CreateWorkoutFragment instance;

    public CreateWorkoutFragment() {
    }

    /*public static CreateWorkoutFragment newInstance()
    {
          if(instance == null)
          {
              instance = new CreateWorkoutFragment();
          }

        return instance;
    } */


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        ViewGroup view = (ViewGroup) inflater.inflate(R.layout.create_workout, null);

        fragmentNavigationHelper = new FragmentNavigationHelper();
        addExerciseButton = (Button) view.findViewById(R.id.addExercise_button);
        addExerciseButton.setOnClickListener( new OnClickListener()
        {
            @Override
            public void onClick(View v) {
                //fragmentNavigationHelper.changeFragmentWithTab((Fragment) new ExerciseCategoryFragment());

                Fragment newFragment = new ExerciseCategoryFragment();
                FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
                transaction.replace(R.id.fragment_container, newFragment);
                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                transaction.addToBackStack(null);
                transaction.commit();
            }
        });

        return view;
    }
} 

createWorkout.xml 内にすべてがラップされている相対レイアウトの ID を使用しているため、問題が発生している可能性があると思います

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/createWorkout_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/createWorkoutTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:contentDescription="@string/begin_workout_title_description"
        android:src="@drawable/create_workout_image"
        android:visibility="visible" />

    <TextView
        android:id="@+id/day_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/createWorkoutTitle"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="19dp"
        android:layout_marginLeft="14dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/dateMonth_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/day_textview"
        android:layout_alignParentRight="true"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/addExercise_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />

    <Button
        android:id="@+id/NFCToggle_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@+id/addExercise_button"  />

</RelativeLayout>

私は本当に困惑しており、答えに近づくものを見つけることができないように見えるので、正しい方向への助けやプッシュは大歓迎です。

前もって感謝します

4

0 に答える 0