-2

I'm working on tabactivity's fragment but i'm facing an issue like When i swipe the tab fragment then same UI of tab1 will appear on tab2 i.e.Switch case is not working properly inside placeholder class.While Tab1 and Tab2 having different UI. Please help me i'm new to android.

 public View onCreateView(
        @NonNull LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main_tab, container, false);


    View root = null;
    switch (1) {
        case 1:
            root = inflater.inflate(R.layout.fragment_main_tab, container, false);
            break;
        case 2:
            root = inflater.inflate(R.layout.fragment_team_screen_, container, false);
            break;
    }

    Next = (ImageButton) rootView.findViewById(R.id.btn_expand);
    Next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            updatedetails();
        }
    });

    return rootView;
}

2 Answers2

1

Becuase you have done the mistake in swtich statement

switch (1) { // 1 for all the condition
        case 1:
            root = inflater.inflate(R.layout.fragment_main_tab, container, false);
            break;
        case 2:
            root = inflater.inflate(R.layout.fragment_team_screen_, container, false);
            break;
    }

you need to pass the position here like this

switch (position) { // here position of the fragment
        case 1:
            root = inflater.inflate(R.layout.fragment_main_tab, container, false);
            break;
        case 2:
            root = inflater.inflate(R.layout.fragment_team_screen_, container, false);
            break;
    }
Sunny
  • 3,134
  • 1
  • 17
  • 31
0

You need to pass tab position like,

switch (tabPosition) { // here position of the fragment to show
    case 1:
        // your code logic
        break;
    case 2:
        // your code logic
        break;
}
Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Rohit J
  • 107
  • 7
  • can you tell me is it ok to place this code inside OnCreateView of placeholder class –  Jun 28 '19 at 06:43
  • After the onCreate() is called in Fragment, the Fragment's onCreateView() is called, so it will be fine. – Rohit J Jun 28 '19 at 07:36