1

I have an activity , which holds two fragments via view pager. I have an arraylist displayed on fragment A, and a list view of items in fragment B. When I check some of these items and click on a button they are passed to the array list of fragment A and should be displayed first.

The data does pass to fragment A as it is supposed to. The problem is that it doesn't display the refreshed array list.

I tried making the ViewPager member static, and then pass it to fragment A every time I click that button in fragment B to pass the content to fragment A. Then in fragment A I do notifyDataSetChanged() on that adapter member. It still doesn't work though.

public class PagerActivity extends FragmentActivity implements  MainFragment.AddToHistoryInterface
{
    static ViewPagerAdapter adapter;

@Override
protected void onCreate( Bundle savedInstanceState ) 
{
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_pager );

    ViewPager viewPager = ( ViewPager ) findViewById( R.id.viewPager );
    adapter = new ViewPagerAdapter( getSupportFragmentManager() );
    viewPager.setAdapter( adapter );
}


public static void removeFromB( List<Password> listFromB )
{
    MainFragment.fromBtoA( listFromB, adapter );
}

Then, in fragment A: .... ...

public static void fromHistoryToMain( List<Password> listBackToMain, ViewPagerAdapter adapter )
    {
        passwordsList.addAll( 0, listBackToMain );
        adapter.notifyDataSetChanged();
    }
BVtp
  • 2,308
  • 2
  • 29
  • 68
  • Your answer is here: http://stackoverflow.com/questions/16671695/how-to-recreate-all-fragments-in-viewpager – MarkySmarky Jul 16 '15 at 12:32
  • Unfortunately it didn't help. I tried doing exactly as it stated in the accepted answer there. Thank you though for referring me to that link – BVtp Jul 16 '15 at 12:35
  • you are using wrong adapter ... you don't wana update adapter which generates pages ... but adapter used to display data on one page .... anyway nice one content provider + loaders api would do the thing – Selvin Jul 16 '15 at 12:37

0 Answers0