I've been following this tutorial: https://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html on how to use fragmentstatepageradapters. It works well but I can't seem to be able to use the ArrayListFragment's instance number. In the tutorial there is this bit displaying the instance number as a header:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
View tv = v.findViewById(R.id.text);
((TextView)tv).setText("Fragment #" + mNum);
...
When I start the app the first screen show Fragment 0. when I swipe to the next screen it shows Fragment 1 and so forth. But when I add this:
Log.i("instancenumber", Integer.toString(mNum));
right below ((TextView)tv)...
the log shows
instancenumber 0
instancenumber 1
right when I start the app before I even touched anything and when I swipe right it switches to 2 and when I swipe to the last one it doesn't log anything and going backwards somehow also doesn't update correctly.
I'm guessing I'm not understanding either the concept of instance numbers or the onCreateView method correctly. How can I get the correct instance number? It seems to work with the textview.
thanks in advance,
hachel
PS: context: I need the number because I have an mp3 playing and I want it to play faster (playback speed calculated by increasing instance number) and I also display a new image when I swipe to the next screen