-1

I have different Fragment set for each category and want to show them when selected from drawer

private static final String ARG_POSITION = "position";

    private int position;
    private LinearLayout layout;
    private TextView icon;

    public static WizardUniversalFragment newInstance(int position) {
        WizardUniversalFragment f = new WizardUniversalFragment();
        Bundle b = new Bundle();
        b.putInt(ARG_POSITION, position);
        f.setArguments(b);
        return f;
    }

How can I solve this?

Ali Khaki
  • 1,184
  • 1
  • 13
  • 24
Syed Ali Shahzil
  • 1,079
  • 1
  • 11
  • 17
  • 1
    Welcome to SO, please take some time to search before question. You will find many blogs and answers telling the way to implement Navigation Drawer with Fragments. Like this one. https://stackoverflow.com/a/36079506/6891563 – Khemraj Sharma Nov 01 '18 at 13:20
  • 1
    Possible duplicate of [Android - How to change fragments in the Navigation Drawer](https://stackoverflow.com/questions/24006181/android-how-to-change-fragments-in-the-navigation-drawer) – Khemraj Sharma Nov 01 '18 at 13:21
  • sorry i am new to SO next time i will be more careful before asking question Thank you for your support – Syed Ali Shahzil Nov 01 '18 at 13:27

1 Answers1

1

You call Each Fragment by their position.

From your code i have understand the declaration of your position argument use that to call each Fragment

 @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            position = getArguments().getInt(your_pos);
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_wizard_universal,
                    container, false);
            layout = (LinearLayout) rootView
                    .findViewById(R.id.Your_fragment);
            icon = (TextView) rootView
                    .findViewById(R.id.Your_fragment_icon);

            if (position == 0) {
                layout.setBackgroundColor(ContextCompat.getColor(getContext(),
                        R.color.#));
                layout.invalidate();
                icon.setText(R.string.#);
            } 

            ViewCompat.setElevation(rootView, 50);
            return rootView;
        }

Set that and you are good to go

Ahmed Mujtaba
  • 744
  • 5
  • 16