Note that there are some explanatory texts on larger screens.

plurals
  1. POview pager with fragments having listview updating multiple times
    primarykey
    data
    text
    <p>I am trying to implement 3 fragments within View pager. All of the fragments has their own list view. Whenever i am swiping back to the first fragment the list view is updating itself getting duplicate values. here is the main activity implementing the view pager. Please suggest.</p> <pre><code>public class MainActivity extends FragmentActivity { /** Called when the activity is first created. */ static AppSectionsPagerAdapter mAppSectionsPagerAdapter; ViewPager mViewPager; SearchView mSearchView; MenuItem menuSearch; Boolean flag = false; String pid; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setupActionBar(); getActionBar().setTitle("All Patients"); mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new OnPageChangeListener() { public void onPageSelected(int position) { //mAppSectionsPagerAdapter.getItemPosition(getFragmentManager().findFragmentById(position)); //getActionBar().setTitle(mAppSectionsPagerAdapter.getPageTitle(position)); if(position==0){ getActionBar().setTitle("All Patients"); //flag = true; //menuSearch.setVisible(true); invalidateOptionsMenu(); } if(position==1){ getActionBar().setTitle("All Doctors"); //flag=false; //menuSearch.setVisible(false); invalidateOptionsMenu(); } else getActionBar().setTitle("All Nurses"); invalidateOptionsMenu(); } public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_DRAGGING) { } if (state == ViewPager.SCROLL_STATE_IDLE) { } } }); } /** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to one of the primary * sections of the app. */ public static class AppSectionsPagerAdapter extends FragmentPagerAdapter { public AppSectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { switch (i) { case 0: // The first section of the app is the most interesting -- it offers // a launchpad into the other demonstrations in this example application. return new AllPatient(); case 1: //Intent intent = new Intent(MainActivity.this,abc.class); return new AllDoctors(); case 2: return new AllNurses(); } return null; } @Override public int getCount() { return 3; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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