Code example for Fragment

Methods: setArguments

0
    public static SampleFragment newInstance(int position) {
 
        SampleFragment sampleFragment = new SampleFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("position", position);
        sampleFragment.setArguments(bundle);
 
        return sampleFragment;
    } 
 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
        Bundle bundle = getArguments();
        int position = 0;
        if (bundle != null) {
            position = bundle.getInt("position");
        } 
 
        View view = inflater.inflate(R.layout.fragment_main, container, false);