Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
133 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...