0

I have 3 fragment in a viewpager which implemented from FragmentStatePagerAdapter.

I want only middle fragment refreshed, because I have an animation listener in it. Because of this I tried this code:

@Override
public int getItemPosition(Object object) {
    if (object instanceof MiddleFragment){
        return POSITION_NONE;
    }else {
        return POSITION_UNCHANGED;
    }

but not work for me, because setOffscreenPageLimit default value is 1, I dont see any refresh from middle fragment. I have no any idea for doing that.


Please guide me, Thanks in advance.

Naruto Uzumaki
  • 2,019
  • 18
  • 37

2 Answers2

0

Maintain an ArrayList of the fragments that your are adding in the viewpager. You can than retrieve the fragment from the arrayList and perform the update. See if it works!!!

Edit 1: I am adding a sample for this.

  ArrayList<Fragments> arrayList = new ArrayList<Fragment>();

In the getItem method of the your fragmentpageradapter , before returning each item , add it to the arraylist

    @Override
    public Fragment getItem(int position) {
           Fragment f = new YourFragment();
             arrayList.add(f);
            return f;
    }

When you are willing to update the second fragment, you can retrieve that fragment from the arraylist via the given position and perform whatever update you want to do in it.

umesh lohani
  • 162
  • 1
  • 4
  • 13
0

You can refresh your fragment by one of this two ways,

1. Use refresh() method.

protected PopulareFragment populareFragment;

if(current_tab.contains("Middle Fragment")){
    populareFragment.refresh();
}

2. Or simply add mTabHost.setCurrentTab(2); into the callback.

Apurva
  • 7,871
  • 7
  • 40
  • 59
  • tnx for reply, I dont see any method such `refresh` and I have any tab. I implemented middle fragment from `Updateable` interface, but my problem is: middle fragment after first call never called again. – Naruto Uzumaki Mar 15 '15 at 07:08