Basically I have two tabs. A Fragment and a ListFragment.
When in the Fragment, you can insert data into a Database that will populate a ListView in the ListFragment Tab directly next to it. I want to be able to swipe to that ListFragment (after inserting new data) and while using the ViewPager function for swiping, I want the ListView to refresh.
Is there a proper way to do this? I can show code if requested; but not sure which code to show. To start, here is my View pager setup:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_layout);
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayHomeAsUpEnabled(true);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
Please note: This is NOT a dual pane setup.
The proper way to do it is to have your
ListFragmentimplement theLoaderManager.LoaderCallbacks<D>interface and initialize aLoaderto load the data being bound to theListView.You can read this blog post to learn more about
Loaders.