I have an Activity which extends ActionBarActivity and activity has following code in xml.
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
It has just ViewPager. I want to display Image with list of options so I opted for creating a fragment with layout I want to be shown as a part of ViewPager.
I created an adapter extending FragmentPagerAdapter as follows:
private class CategoryViewPagerAdapter extends FragmentStatePagerAdapter {
public CategoryViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int currentPosition) {
return FullScreenFragment.newInstance(fragments
.get(currentPosition));
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return fragments.size();
}
}
Where fragments is list of Strings.
It loads Images and Swipes also work however Image shown has title which is of previous image.
THis title is basically set in ActionBar for that fragment.
In my fragment class I did this:
parentActivity = (ActionBarActivity) getActivity();
parentActivity.getSupportActionBar().setDisplayOptions(
ActionBar.DISPLAY_SHOW_CUSTOM);
parentActivity.getSupportActionBar().setCustomView(
R.layout.full_screen_action_bar);
And also sometimes few components with in fragment layout dont rendered on click a button within fragment. Do i need to findId from Activity or Fragment rootView
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…