How does TabLayout load when it is selected?

  android, question

How does TabLayout load when it is selected?
I wrote a TabLayout, but when I started the application, I already loaded all the tabs under the tab. What I want to realize is to click on a tab and then load the fragment under this tab, just like Zhihu. How do I realize this function?
Attach

public class MainActivity extends AppCompatActivity {
 
 @BindView(R.id.mainLinearLayout)
 LinearLayout mainLinear;
 @BindView(R.id.mainContent)
 FrameLayout mainContent;
 @BindView(R.id.tabHost)
 FragmentTabHost tabHost;
 @BindView(R.id.tabContent)
 FrameLayout tabContent;
 
 private LayoutInflater inflater;  //for loading view
 private List<MainTabs> mTabs = new ArrayList<>(4);  //for storing the contents of each tag
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 ButterKnife.bind(this);
 initBmob();
 initTab();
 bracket
 
 private void initBmob() {
 ////First: Default Initialization
 //        Bmob.initialize(this, "67d2f18dc98bf4f958229765bc8b0b06");
 
 
 //Second: Starting from v3.4.7, BmobConfig is set to allow setting of request timeout time, file slice upload size, file expiration time (in seconds).
 BmobConfig config = new BmobConfig.Builder(this)
 //Set appkey
 .setApplicationId("67d2f18dc98bf4f958229765bc8b0b06")
 //Request timeout (in seconds): default 15s
 .setConnectTimeout(30)
 //Size of each file slice (unit byte) when uploading file slices, default 512*1024
 .setUploadBlockSize(1024 * 1024)
 //Expiration time of file (in seconds): default 1800s s.
 .setFileExpiration(2500)
 .build();
 Bmob.initialize(config);
 bracket
 
 private void getPermission() {
 PermissionManager helper;
 helper = PermissionManager.with(MainActivity.this);
 //Add Permission Request Code
 //        helper.addRequestCode(10)
 bracket
 
 private void initTab() {
 //Tab object
 MainTabs tabs1 = new MainTabs ("home page", r.drawable.tab _ icon _ 1 _ selector, fragment _ 1.class);
 Maintabs2 = newmaintabs2 ("record", r.drawable.tab _ icon _ 2 _ selector, fragment _ 2.class);
 Main tabs3 = newmain tabs3 ("discovery", r.drawable.tab _ icon _ 3 _ selector, fragment _ 3.class);
 MainTabs tabs4 = new MainTabs ("i", r.drawable.tab _ icon _ 4 _ selector, fragment _ 4.class);
 
 mTabs.add(tabs1);
 mTabs.add(tabs2);
 mTabs.add(tabs3);
 mTabs.add(tabs4);
 
 inflater = LayoutInflater.from(this);
 //The view representing the main content is the defined fragment internal view
 tabHost.setup(this, getSupportFragmentManager(), R.id.mainContent);
 
 //Take out each one and set it up
 for (MainTabs mainTabs : mTabs) {
 //Get Text Label
 TabHost.TabSpec tabSpec = tabHost.newTabSpec(mainTabs.getTitle());
 tabSpec.setIndicator(buildTabs(mainTabs));
 tabHost.addTab(tabSpec, mainTabs.getFragment(), null);
 bracket
 //        fragmentTabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);  //Remove the dividing line?
 tabHost.setCurrentTab(0);
 
 bracket
 
 //Pass in an object and return a View
 private View buildTabs(MainTabs mainTabs) {
 View view = inflater.inflate(R.layout.tab_indicator, null);
 ImageView imageView = (ImageView) view.findViewById(R.id.tab_icon);
 TextView textView = (TextView) view.findViewById(R.id.tab_text);
 
 //Set up pictures and text
 imageView.setBackgroundResource(mainTabs.getIcon());
 textView.setText(mainTabs.getTitle());
 return view;
 bracket
 bracket

It is recommended that you use tablayout plus viewpager plus fragment to make the layout, and then set the Load On Demand mechanism of viewpager.
ViewPager caching mechanism