In your getItem method, you create a new instance of the fragment. This is terrible. This puts you in the situation you are currently in. What you do is create a new object that will reside in it, as you indicated. But when the evil Android system decides that you need to talk to your snippet again and request it from your adapter, you tell it "No, I don't want to!" and instead giving him a new piece EXACTLY the same as his older roter.
To fix this, you inflate the entire fragment in advance and then return the correct fragment. Or, if you want, do not do this. But keep a record of the instances you created so that you can return fragments already created.
I don’t know exactly why it is called twice - I didn’t look at the v4 source, but this is probably done to ensure that the element was actually extracted, or the system entered a state in which the previous element should be referenced,
Finally, save the created instances - particularly for an object as heavy as fragments, views and actions.
class Adapter extends MyWhateverAdapter { Fragment[] myLovelyFragments; public Adapter() {
source share