There are three fragments. On 1 (start) two buttons are placed to jump to other fragments, on the other one buttons to go back to 1 (start). On 2 fragments - two Сheckbox and on 3 fragments - ImageView for downloading pictures from the gallery. Fragments are placed in the ViewPager . If I tick Checkbox and make transitions between 1 and 2 fragments, then everything is fine. But if from 2 I return to 1, and then I go to 3 and then I return to 2 again, then the Checkbox flies. The same problem with the image for ImageView . But the Spinner , which is on the 3rd fragment, works normally without a reset, as if not crossing, between the fragments.
How to disable a reset? What could be the problem? Where to look?
Switching between fragments do this:
((MainActivity) getActivity()).setPage(MainActivity.FRAGMENT_TWO); Class MainActivity where I create fragments:
public class MainActivity extends FragmentActivity { public static final int FRAGMENT_ONE = 0; public static final int FRAGMENT_TWO = 1; public static final int FRAGMENT_THREE = 2; public static final int FRAGMENTS = 3; // адаптер фрагментов. private FragmentPagerAdapter _fragmentPagerAdapter; // список фрагментов для отображения. private final List<Fragment> _fragments = new ArrayList<Fragment>(); // ViewPager который будет все это отображать. private ViewPager _viewPager; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // создаем фрагменты. _fragments.add(FRAGMENT_ONE, new FirstFragment()); _fragments.add(FRAGMENT_TWO, new SecondFragment()); _fragments.add(FRAGMENT_THREE, new TherdFragment()); _fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { ..... }; _viewPager = (ViewPager) findViewById(R.id.pager); _viewPager.setAdapter(_fragmentPagerAdapter); _viewPager.setCurrentItem(1); _viewPager.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View arg0, MotionEvent arg1) { return true; } }); }
public void setPage(int page) { _viewPager.setCurrentItem(page, true); } }