Android : in swipe tabs how to keep the tab no reopen when u swipe more then one tab

on Monday, October 27, 2014


i have swipe tabs with 3 tab i first tab will have web view with Facebook other got text only , now if i swipe from first tab to the second then come back to the first its good but if i swipe to the 3rd tab when i go back to the first tab the web view will reload again , how can i stop that


this is my code home.java



public class MainActivity extends FragmentActivity {
ViewPager Tab;
TabPagerAdapter TabAdapter;
ActionBar actionBar;

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

TabAdapter = new TabPagerAdapter(getSupportFragmentManager());

Tab = (ViewPager)findViewById(R.id.pager);
Tab.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {

actionBar = getActionBar();
actionBar.setSelectedNavigationItem(position); }
});
Tab.setAdapter(TabAdapter);

actionBar = getActionBar();
//Enable Tabs on Action Bar
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener(){

@Override
public void onTabReselected(android.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub

}

@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {

Tab.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(android.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub

}};
//Add New Tab
actionBar.addTab(actionBar.newTab().setText("Android").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("iOS").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("Windows").setTabListener(tabListener));

}


}


0 comments:

Post a Comment