Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title Indicators are not moving #5

Closed
ManojMM026 opened this issue May 2, 2013 · 11 comments
Closed

Title Indicators are not moving #5

ManojMM026 opened this issue May 2, 2013 · 11 comments

Comments

@ManojMM026
Copy link

Hi, I found your library example very use full. But when i tried using PagerSlidingTabStrip it does not move as a change Page in ViewPager!.

Here is my xml

       <com.astuetz.viewpager.extensions.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="48dip"
        android:background="@drawable/background_tabs"
        android:visibility="visible" />

     <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/indicator"
        android:layout_below="@+id/tabs"
        android:layout_margin="25dp"
        android:visibility="visible" />

This is my code

 private PagerSlidingTabStrip tabs;
 mPager=(ViewPager)findViewById(R.id.viewPager);
     tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    pages.add("Location");
    pages.add("Register");
    pages.add("Description");
pages.add("Businesshours");
pages.add("Signup");

mPager.setAdapter(adapter);
tabs.setViewPager(mPager);

//Creating Pages with PageAdapter.

     public class PageAdapter extends FragmentStatePagerAdapter
     {
     Context context;
     ArrayList<String> pages;




    public PageAdapter(FragmentManager fm,Context context,ArrayList<String> pages) {
        super(fm);
        // TODO Auto-generated constructor stub
        this.context=context;
        this.pages=pages;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        // TODO Auto-generated method stub
        return pages.get(position);
    }

    @Override
    public Fragment getItem(int position) {
        // TODO Auto-generated method stub
        return new PageFragment(pages.get(position), context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return pages.size();
    }



    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // TODO Auto-generated method stub

        FragmentManager manager = ((Fragment) object).getFragmentManager();
        FragmentTransaction trans = manager.beginTransaction();
        trans.remove((Fragment) object);
        trans.commit();

        super.destroyItem(container, position, object);
    }
}
@ghost
Copy link

ghost commented May 2, 2013

Hey, where do you set the Adapter for the ViewPager?
It should be done BEFORE the call to tabs.setViewPager(mPager), otherwise
you have to call tabs.notifyDataSetChanged() after setting or changing the
Pager's adapter

On Thu, May 2, 2013 at 10:31 AM, ManojMM026 notifications@github.comwrote:

Hi, I found your library example very use full. But when i tried using
PagerSlidingTabStrip it does not move as a change Page in ViewPager!.

Here is my xml

   <com.astuetz.viewpager.extensions.PagerSlidingTabStrip
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="48dip"
    android:background="@drawable/background_tabs"
    android:visibility="visible" />

 <android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/indicator"
    android:layout_below="@+id/tabs"
    android:layout_margin="25dp"
    android:visibility="visible" />

This is my code

private PagerSlidingTabStrip tabs;
mPager=(ViewPager)findViewById(R.id.viewPager);
tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
pages.add("Location");
pages.add("Register");
pages.add("Description");
pages.add("Businesshours");
pages.add("Signup");
tabs.setViewPager(mPager);

//Creating Pages with PageAdapter.

 public class PageAdapter extends FragmentStatePagerAdapter
 {
 Context context;
 ArrayList<String> pages;




public PageAdapter(FragmentManager fm,Context context,ArrayList<String> pages) {
    super(fm);
    // TODO Auto-generated constructor stub
    this.context=context;
    this.pages=pages;
}

@Override
public CharSequence getPageTitle(int position) {
    // TODO Auto-generated method stub
    return pages.get(position);
}

@Override
public Fragment getItem(int position) {
    // TODO Auto-generated method stub
    return new PageFragment(pages.get(position), context);
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return pages.size();
}



@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    // TODO Auto-generated method stub

    FragmentManager manager = ((Fragment) object).getFragmentManager();
    FragmentTransaction trans = manager.beginTransaction();
    trans.remove((Fragment) object);
    trans.commit();

    super.destroyItem(container, position, object);
}

}


Reply to this email directly or view it on GitHubhttps://github.com//issues/5
.

@ManojMM026
Copy link
Author

yah I have done it after setting adapter.I have updated my code! @astuetz

mPager.setAdapter(adapter);
tabs.setViewPager(mPager);

@ghost
Copy link

ghost commented May 2, 2013

Ok, what device & android version are you using?

On Thu, May 2, 2013 at 10:38 AM, ManojMM026 notifications@github.comwrote:

yah i have done it after setting adapter

mPager.setAdapter(adapter);
tabs.setViewPager(mPager);


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-17326441
.

@ManojMM026
Copy link
Author

Sorry to bother you. I forgot to set PageChangeListener to tab.! It's working fine! Thanks for awesome library!.

@ghost
Copy link

ghost commented May 2, 2013

Good to hear, thanks! :)

On Thu, May 2, 2013 at 11:01 AM, ManojMM026 notifications@github.comwrote:

Sorry to bother you. I forgot to set PageChangeListener to tab.! It's
working fine! Thanks for awesome library!.


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-17327361
.

@astuetz astuetz closed this as completed May 2, 2013
@ManojMM026
Copy link
Author

@astuetz but have one more doubt. In your example strip under title flows smoothly with pages. Whether in my app i am getting jerky performance !.

@ghost ghost assigned astuetz May 2, 2013
@ghost
Copy link

ghost commented May 3, 2013

Are you doing some extra work in your OnPageChangeListener? Also overloaded fragments can cause some janks while swiping

@rimzinou
Copy link

please help me to solve my problem:
i download the PagerSlidingTabStrip project https://github.com/astuetz/PagerSlidingTabStrip
but when i import this project i have errors in the library
i don't now what's the raison
thx to help me

@ahtrak
Copy link

ahtrak commented Nov 4, 2014

Hello, my tabs change only on sliding and not on clicking, how do I fix this?

@naveedahmad99
Copy link

Worked fine when I removed the viewPager.setOnChangeListener(this);
to
PageIndicator.setOnChangeListener(this);

Working fine with sliding and on click also

@VMMobility
Copy link

How can I set icons with the Tab names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants