0

I have 2 tabs A and B. Tab A contains fields that must be entered by the user. If the user clicks tab B, I am calling my validate routine in a "OnTabSelectedListener". The problem I have is when I want to stop the tab change and keep the user on Tab A to fill out the required fields. Is there a way to accomplish this within the OnTabSelectedListener?

  • Welcome to SO, Refer [this](https://stackoverflow.com/help/how-to-ask) to frame your questions properly. Post your code. – harshavmb Jun 06 '17 at 16:38

3 Answers3

0

This question has answers that shows you how to select a tab programatically but, in my opinion, you should block the user's swipe and put a button to change tabs and validate

Gabriel Costa
  • 341
  • 1
  • 10
0

In OnTabSelectedListener method onTabSelected() is invoked when tab change has already happened, so all you can do is check user input and switch back to tab A if input validation failed.

0

Thank you Pavel & Gabriel for replying. I ended up going without a view pager and changing the tab fragments manually with tab.select() in the onTabSelected method. This allowed me to do a validate then switch back to the original tab if data was not entered correctly. Surprisingly there is no "flash" on the screen when I switch back to the original tab. All runs smoothly. Also, since I couldn't use the view pager, I added a GestureListener and changed the tabs on Swipe Left & Right.