Referencing the following answer, I tried to unimplement what I was currently doing in a project, i.e., using the following code:
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
Because due to the current implementation all the pages in my ViewPager
was reloaded again. The reason as to why I implemented this in the 1st place was to reload a fragment (which was dynamic according to the user input).
After reading the reference, I got a vague idea on what I was supposed to do, I overrode the instantiateItem()
method, but in my attempt to setTag()
I got confused as to how I was to implement this. I did try the following:
@Override
public Object instantiateItem(ViewGroup viewgroup, int position) {
// TODO Auto-generated method stub
View viewA = viewgroup.getChildAt(0);
viewA.setTag("FragmentA");
View viewB = viewgroup.getChildAt(1);
viewB.setTag("FragmentB");
View viewC = viewgroup.getChildAt(2);
viewC.setTag("FragmentC");
return super.instantiateItem(viewgroup, position);
}
And in my interface implementation I called the following:
PlayingFragment fragment = new PlayingFragment();
fragment.setArguments(element);
getSupportFragmentManager().beginTransaction().add(fragment,"NowPlaying").commit();
adapter.notifyDataSetChanged();
pager.findViewWithTag("FragmentC");
The current implementation gives me a NullPointerException
at : viewA.setTag("FragmentA");
Can someone help me implement this setTag()
and findViewWithTag()
implementation ?