use of android.support.v4.app.FragmentPagerAdapter in project BoomMenu by Nightonke.
the class FragmentActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
assert viewPager != null;
viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return new BMBFragment().position(position);
}
@Override
public int getCount() {
return 50;
}
});
}
use of android.support.v4.app.FragmentPagerAdapter in project LuaViewSDK by alibaba.
the class FixedFragmentStatePagerAdapter method instantiateItem.
@Override
public Object instantiateItem(ViewGroup container, int position) {
final Object fragment = super.instantiateItem(container, position);
try {
final Field saveFragmentStateField = Fragment.class.getDeclaredField("mSavedFragmentState");
saveFragmentStateField.setAccessible(true);
final Bundle savedFragmentState = (Bundle) saveFragmentStateField.get(fragment);
if (savedFragmentState != null) {
savedFragmentState.setClassLoader(Fragment.class.getClassLoader());
}
} catch (Exception e) {
Log.w("FragmentPagerAdapter", "Could not get mSavedFragmentState field: " + e);
}
return fragment;
}
use of android.support.v4.app.FragmentPagerAdapter in project AndroidAutoLayout by hongyangAndroid.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("标题");
setSupportActionBar(toolbar);
mTabLayout = (TabLayout) findViewById(R.id.id_tablayout);
mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return new SimpleFragment();
}
@Override
public int getCount() {
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
return "Page " + position;
}
});
mTabLayout.setupWithViewPager(mViewPager);
}
use of android.support.v4.app.FragmentPagerAdapter in project StatusBarUtil by laobie.
the class UseInFragmentActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_use_in_fragment);
mVpHome = (ViewPager) findViewById(R.id.vp_home);
mBottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.ic_favorite, "One")).addItem(new BottomNavigationItem(R.drawable.ic_gavel, "Two")).addItem(new BottomNavigationItem(R.drawable.ic_grade, "Three")).addItem(new BottomNavigationItem(R.drawable.ic_group_work, "Four")).initialise();
mBottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
@Override
public void onTabSelected(int position) {
mVpHome.setCurrentItem(position);
}
@Override
public void onTabUnselected(int position) {
}
@Override
public void onTabReselected(int position) {
}
});
mFragmentList.add(new ImageFragment());
mFragmentList.add(new SimpleFragment());
mFragmentList.add(new SimpleFragment());
mFragmentList.add(new SimpleFragment());
mVpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
mBottomNavigationBar.selectTab(position);
switch(position) {
case 0:
break;
default:
Random random = new Random();
int color = 0xff000000 | random.nextInt(0xffffff);
if (mFragmentList.get(position) instanceof SimpleFragment) {
((SimpleFragment) mFragmentList.get(position)).setTvTitleBackgroundColor(color);
}
break;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
mVpHome.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
});
}
use of android.support.v4.app.FragmentPagerAdapter in project quickstart-android by firebase.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the adapter that will return a fragment for each section
mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
private final Fragment[] mFragments = new Fragment[] { new RecentPostsFragment(), new MyPostsFragment(), new MyTopPostsFragment() };
private final String[] mFragmentNames = new String[] { getString(R.string.heading_recent), getString(R.string.heading_my_posts), getString(R.string.heading_my_top_posts) };
@Override
public Fragment getItem(int position) {
return mFragments[position];
}
@Override
public int getCount() {
return mFragments.length;
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentNames[position];
}
};
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
// Button launches NewPostActivity
findViewById(R.id.fab_new_post).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, NewPostActivity.class));
}
});
}
Aggregations