I have a ViewPager with pages of WebView. A page has a text field allowing the user to type in contents. I'd like to save the page's input text to a Java variable when moving between pages (by sliding forward/backward).
Unfortunately, it seems onPageSelected only tells me the page number that is about to display, and not the page it came from, which means I can't tell which page I needed to save at the time when the user changes page.
Any ideas? Many thanks in advance!
You can store the last known page index in a field at the end of onPageSelected
(initialize it with an appropriate default when your activity starts). Then, inside onPageSelected
, you check that field to see what page the user was previous on.
private int mLastPage;
@Override
public void onPageSelected(int position) {
// save the information from the page at mLastPage
mLastPage = position;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With