title: Android Java Viewpager loads in the same viewPager view position
body: <p>I'm new in Java/Android programming.</p>
  
  <p>I've got a Fragment with tabLayout and viewPager. This fragment get's a list of groupId/groupName from the server then needs to create one page for each groupId. It sends the value to the adapter (the fragment to show in the viewpager pages is always ContentRoster() but the groupId define the data to show)</p>
  
  <p>My issue is that this ContentRoster() fragment only loads in position 0 of the viewpager. I can swipe and slect the tabs as expected, but all loads in the same view...</p>
  
  <p>If I have two sets of groupId, the first one will load in position 0, then the second one groupId#2 (which is autoloaded to populate next view) update position 0 view and erase groupID#1 view.</p>
  
  <pre><code>    protected void onPostExecute(ArrayList&lt;HashMap&lt;String, String&gt;&gt; result) {
          super.onPostExecute(result);
  
          TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tabLayout);
          final ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager);
          tabLayout.setupWithViewPager(viewPager);
  
          AdapterViewPager mCustomPagerAdapter = new AdapterViewPager(getChildFragmentManager());
  
          //add Fragment with specific arguments
          for(int i = 0; i &lt; result.size() ; i++) {
              mCustomPagerAdapter.addFragment(new ContentRoster(), (result.get(i)).get("groupname"), (result.get(i)).get("groupid") );
          }
  
          //Set adapter if not null
          if (viewPager != null) {
              viewPager.setAdapter(mCustomPagerAdapter);
              viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
          }
  
          tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
                  if (viewPager != null) {
                      Log.i("#TAB_POS", "" + tab.getPosition());
                      viewPager.setCurrentItem(tab.getPosition());
                  }
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
  
              }
  
              @Override
              public void onTabReselected(TabLayout.Tab tab) {
                  if (viewPager != null) {
                      Log.i("#TAB_POS", "" + tab.getPosition());
                      viewPager.setCurrentItem(tab.getPosition());
                  }
              }
          });
  
      }
  </code></pre>
  
  <p>The adapter looks like this :</p>
  
  <pre><code>import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.util.Log;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class AdapterViewPager extends FragmentPagerAdapter {
  
      private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentParamsList = new ArrayList&lt;&gt;();
  
      public void addFragment(Fragment fragment, String title, String params) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
          mFragmentParamsList.add(params);
      }
  
      public AdapterViewPager(FragmentManager manager) {
          super(manager);
      }
  
      @Override
      public Fragment getItem(int position) {
          String groupId = mFragmentParamsList.get(position);
          Fragment fragment = ContentRoster.newInstance(groupId);
          return fragment;
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
  
  }
  </code></pre>
  
  <p>and the ContentRoster() Fragment is like this :
  I retrieve the groupId from the bundle and 'LoadRosterList().execute(groupId)' charge the data and show only the groupId data in line with the selected tab. </p>
  
  <pre><code>   public static ContentRoster newInstance(String groupId) {
          ContentRoster ContentRoster = new ContentRoster();
  
          Bundle args = new Bundle();
          args.putString("groupId", groupId);
          ContentRoster.setArguments(args);
  
          return ContentRoster;
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          View view = inflater.inflate(R.layout.content_listview, container, false);
  
          Bundle args = getArguments();
          groupId = args.getString("groupId");
  
          progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
          new LoadRosterList().execute(groupId);
  
          return view;
      }
  </code></pre>
  
  <p>UPDATE :
  Could this be link to the last part where I update the listview in the ContentRoster Fragment (which is shown in the viewPager)
  As I get the listview Id from the activity?</p>
  
  <pre><code>protected void onPostExecute(ArrayList&lt;HashMap&lt;String, String&gt;&gt; result) {
      super.onPostExecute(result);
  
      try {
          // Getting adapter by passing xml data ArrayList
          ListView mListView;
          mListView = (ListView) getActivity().findViewById(R.id.listView);
  
          AdapterRoster adapter = new AdapterRoster(getActivity().getApplicationContext(), result);
          mListView.setAdapter(adapter);
          adapter.notifyDataSetChanged();
  
          progressBar.setVisibility(View.GONE); //Effacage du Progress Bar
  
          mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id){
                  // Send intent to SingleViewActivity
                  Intent i = new Intent(getActivity().getApplicationContext(), ActivitySingleGuardian.class);
                  // Pass image index
                  i.putExtra("psnid", ((TextView) v.findViewById(R.id.psnid)).getText().toString());
                  i.putExtra("rank", ((TextView) v.findViewById(R.id.rank)).getText().toString());
                  i.putExtra("lastplay", ((TextView) v.findViewById(R.id.lastplay)).getText().toString());
                  i.putExtra("bungiename", ((TextView) v.findViewById(R.id.bungiename)).getText().toString());
                  i.putExtra("bungieid", ((TextView) v.findViewById(R.id.bungieid)).getText().toString());
                  i.putExtra("picpath", ((TextView) v.findViewById(R.id.picpath)).getText().toString());
                  i.putExtra("membershipType", ((TextView) v.findViewById(R.id.membershipType)).getText().toString());
                  startActivity(i);
              }
          });
  
      } catch (NullPointerException e) {
          e.printStackTrace();
      }
  }
  </code></pre>