I want to check the data entered by the user in the form field in the individual actions of the onTabChanged tab, but I cannot set more than one setOnTabChangedListener.
There is no need for OnTabChangeListener seconds, and even if you can install it, it will not help you. As you create the code, you need access to child actions. You can do this using one of the answers to this question . The problem is that these answers, with the exception of accepted ones, use outdated methods.
My method, which I suggested in the comments, is to have a static logical field in each of the child actions used as tabs, and to allow all your actions to update this logical flag whenever there is a change in the state of the views in these (if you check CheckBox , type something in EditText , etc.). Then you can simply check the flag for the desired child activity in the OnTabChangeListener . My method should work, but your code is a bit messy, so you have to change it a bit.
I tried to configure the listener in onResume () under the main Parent activity # 1. But the Resume () method has never been called. I also got a null pointer exception.
It's normal that you get a NullPointerException with code, as I have not seen where you initialize the references to the child actions that you use in OnTabChangeListener .
also:
Do not use TabActivity . It is deprecated in favor of the Fragments framework, which is more flexible. These snippets can help you because, I think, you want to stop changing tabs if checking the current page fails, and OnTabChangeListener may be a little late for this (but I may be wrong in what you want).
As a side note, use equals in your code to test String equality, not == .
source share