-1

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

virendrao
  • 1,763
  • 2
  • 22
  • 42

1 Answers1

0

use this method to update action bar

    vp.setOnPageChangeListener(new OnPageChangeListener()
    {

        @Override
        public void onPageSelected(int arg0)
        {
          //update action bar 

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2)
        {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPageScrollStateChanged(int arg0)
        {
            // TODO Auto-generated method stub

        }
    });

And for the second problem , please give more info .

Ratul Ghosh
  • 1,512
  • 9
  • 15
  • Assume I have five image url.. So I am creating same Fragment with five instances each after one url.. In the fragment onCreateView i am loading information for that url such as name of image etc from server... When ViewPager finally gets render it displays image however wrong image name is displayed in action bar its displayed of previous item image in list.... And also when I swipe i want fragment to have its initial view always rather than view which is changed after performing action – virendrao Jul 22 '14 at 13:17