0

I am trying to write an android application but I am fairly new to this, and I'm having issues with selecting different fragments on different tabs. For example, when calling this block of code every tab ends up looking like "location_main.xml." Is there a way to differentiate the tab selected? Thanks!

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.location_main, container,false);
        TextView textView = (TextView) rootView.findViewById(R.id.section_label);

        //This is defining the text for the fragments, or tabs, at the given section number.

        textView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));



        //This returns the View rootView
        return rootView;
    }
Jacob Morris
  • 490
  • 1
  • 6
  • 16
  • I can update my post and add a code sample but I don't know how you create the bas. Are you using a ViewPager or something else? – Elodie E2 Feb 22 '15 at 23:38

2 Answers2

0

You are passing an integer value (ARG_SECTION_NUMBER) in the argument bundle. You can use it to differentiate your tabs. Usually it's used to define the position of the tabs.

You can either change the text of the textview or inflate different layout depending on the getArguments().getInt(ARG_SECTION_NUMBER) value or event instantiate another fragment.

Elodie E2
  • 580
  • 3
  • 10
0

You can check the answer on this question. Has a really good explanation with an example.

How to implement a ViewPager with different Fragments / Layouts

Community
  • 1
  • 1