Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It depends on how different the data is going to be. If every fragment will only have an ImageView you could reuse the same fragment like what you are doing. You just need to check the position in your getItem method and send different data to that instance of the fragment through the bundle. Then inside your DummySectionFragment you can check the data you passed it, even if its just the position, and add a different image depending on the data/position.</p> <p>If the content on each fragment is going to be different, then you should create a different fragment for each section. So instead of having just a DummySectionFragment you would have a different fragment per section and give each one a new layout depending on your needs. </p> <p>Unless you will only use the position to modify the data in each fragment, your getItem should look like this:</p> <pre><code>@Override public Fragment getItem(int position) { Fragment fragment = null; Bundle args = new Bundle(); switch(position){ case 0: fragment = new DummySectionFragment(); args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1); fragment.setArguments(args); break; case 1: fragment = new DummySectionFragment(); args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1); fragment.setArguments(args); break; case 2: fragment = new DummySectionFragment(); args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1); fragment.setArguments(args); break; } return fragment; } </code></pre> <p>The only difference is that if you go with the second approach each case you will instantiate a different fragment and not the same one.</p> <p>If you only want to change the image based on the position of the fragment you can keep your code the same and just check the position inside your DummySectionFragment like this:</p> <pre><code> @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main_dummy, container, false); int position = Integer.toString(getArguments().getInt( ARG_SECTION_NUMBER)) if(position == 1){ //Your on the first tab.. } return rootView; } </code></pre> <p>Good Luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload