How to set values from FragmentContainerView to the fragment in the layout xml file?

94 views Asked by At

I have a Fragment in a FragmentContainerView, and want to send send some parameters to it. Can I do this in layout xml file?

The xml maybe like:

<androidx.fragment.app.FragmentContainerView
    android:name="com.myapp.TestFragment"
    tools:layout="@layout/fragment_test"
    hello="world"/>

then the Java code:

public class TestFragment extends Fragment {
    public void onCreateView(...) {
        getTheValue("hello");  // get "world" here.
    }
}
0

There are 0 answers