Skip to content

How to display a fragment inside the view? #170

@SeakyLuo

Description

@SeakyLuo

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions