There is a ViewPager with 4 pages, which method can track the transition from one tab to another?

This is necessary so that when the tab is "closed", the values ​​from the Edittext saved to the database. For example: the tab of the Users tab is displayed, a slide, or tap-ohm we go to the System tab (the Users tab is closed), Then the values ​​of Edittext ov and checkbox ov are saved in the database (there will be implemented via db.update() .

Here I addTextChangeListener looking for something similar to addTextChangeListener

Here is the view of the application:

Users

enter image description here

    1 answer 1

    to help you with the ViewPager.OnPageChangeListener() :

     pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }); 
    • If you call EditText in onPageScrolled and retrieve information from it, the application crashes with nullPointer (it first calls onPageScrolled and then the entire View page. How can we overcome it? - Yura Geyts
    • do you use fragments? - miha_dev
    • In any case, you need to initialize EditText before scrolling through - miha_dev