PlaceHolderView icon indicating copy to clipboard operation
PlaceHolderView copied to clipboard

How to display a fragment inside the view?

Open SeakyLuo opened this issue 4 years ago • 0 comments

The layout for my view is very simple:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/dialog_food_card_frame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:layout="@layout/fragment_food_card" />

I want to use the FrameLayout to display a fragment, so I tried this but it seems that the FragmentManager could not find the dialog_food_card_frame:

@NonReusable
@Animate(Animate.CARD_TOP_IN_DESC)
@Layout(R.layout.dialog_food_card)
public class FoodCard {
    private FoodCardFragment foodCardFragment = new FoodCardFragment();
    private Food food;
    private Fragment fragment;
    public FoodCard(Fragment fragment, Food food){
        this.fragment = fragment;
        this.food = food;
    }

    @Resolve
    public void onResolved() {
        fragment.getChildFragmentManager().beginTransaction().add(R.id.dialog_food_card_frame, foodCardFragment).commit();
        foodCardFragment.LoadFood(food);
    }
}

How do I display the fragment?

SeakyLuo avatar Dec 11 '19 02:12 SeakyLuo