Back to project page trivial-lists.
The source code is released under:
MIT License
If you think the Android project trivial-lists listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.hbabcock.triviallists; //from w ww .j av a 2s . co m import java.util.UUID; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.util.Log; public class ItemPagerActivity extends FragmentActivity implements ActionBar.TabListener { private static final String TAG = "ItemPagerActivity"; private static final String CURRENT_ITEM = "CURRENT_ITEM"; private ActionBar mActionBar; private Category mCategory; private ViewPager mViewPager; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.item_pager_activity); mActionBar = getActionBar(); mCategory = CategoryItemManager.get(this).getCategory((UUID)getIntent().getSerializableExtra(ItemFragment.EXTRA_CATEGORY_ID)); FragmentManager fm = getSupportFragmentManager(); mViewPager = (ViewPager)findViewById(R.id.pager); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mActionBar.addTab(mActionBar.newTab().setText(R.string.edit).setTabListener(this)); mActionBar.addTab(mActionBar.newTab().setText(R.string.shop).setTabListener(this)); mViewPager.setAdapter(new FragmentPagerAdapter (fm){ @Override public int getCount(){ return 2; } @Override public Fragment getItem(int pos){ if (pos == 0){ return ItemFragmentEdit.newInstance(mCategory.getId()); } else{ return ItemFragmentShop.newInstance(mCategory.getId()); } } }); mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener(){ public void onPageScrollStateChanged(int state){} public void onPageScrolled(int pos, float posOffset, int posOffsetPixels){} public void onPageSelected(int pos){ mActionBar.setSelectedNavigationItem(pos); } }); } @Override public void onPause(){ super.onPause(); Log.i(TAG,"onPause"); CategoryItemManager.get(this).save(); PreferenceManager.getDefaultSharedPreferences(this) .edit() .putInt(CURRENT_ITEM, mViewPager.getCurrentItem()) .commit(); } @Override public void onResume(){ super.onResume(); Log.i(TAG,"onResume"); mViewPager.setCurrentItem(PreferenceManager.getDefaultSharedPreferences(this).getInt(CURRENT_ITEM, 0)); } @Override public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) { } @Override public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) { } }