Android uses fragment to achieve tab effect
Use fragment to achieve tab effect:
Set radiogroup and fragment to achieve tab effect. The key files are:
1. Fragmenttabadapter class:
2.activity_ main. XML layout file:
3. Mainactivity class:
In order to learn the fragment life cycle at the same time, I added log printing in each fragment life cycle method. One has three such fragments. I only post one code, and the rest are the same as this:
In the process of writing, I used RGS at the beginning in order to achieve the effect of clicking the first time to jump to the first fragment if it is not on the home page check(button.getId()); In this method, it is found that the oncheckedchanged listening event will be executed twice, and later changed to button setChecked(true); After this method, the problem is solved successfully.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.