Skip to content
This repository was archived by the owner on Jun 8, 2025. It is now read-only.

Fragment's Arguments Binding

Steven Lewi edited this page Jul 13, 2015 · 3 revisions

@FragmentArgument can be used to bind Fragment's Argument. It has same functionality as getArguments().get...("key");

Container Activity
@ContentView(R.layout.activity_main)
public class MainActivity extends BaseActivity {

    @Override
    protected void onContentViewCreated() {
    }

    @OnClick(R.id.button1)
    public void onButton1Clicked() {
        // Replace fragment with parameters
        Fragment fragment = new ProfileFragment();
        Bundle params = new Bundle();
        params.putString("full_name", "John Doe");
        fragment.setArguments(params);
        replaceFragment(R.id.fragment_container, fragment);
    }
}
Profile Fragment
@ContentView(R.layout.fragment_profile)
public class ProfileFragment extends BaseFragment {

    @FragmentArgument("full_name")
    private String fullName;

    @Override
    protected void onContentViewCreated() {
         Toast.makeText(getActivity(), fullName, Toast.LENGTH_SHORT).show();
    }
}

Clone this wiki locally