Code example for Fragment

Methods: setArguments

    public static SampleFragment newInstance(int position) {
        SampleFragment sampleFragment = new SampleFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("position", position);
        return sampleFragment;
    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);
Connect your IDE to all the code out there  Get Codota for Java