RightActivity.startActivity(getContext(), "You click Android button.") MultipleFragmentRightActivity rightActivity = new MultipleFragmentRightActivity() If in single panel mode, right fragment do not exist. Do not use fragmentBelongActivity.getFragmentManager() method which is not compatible with older android os version.įragmentManager fragmentManager = fragmentBelongActivity.getSupportFragmentManager() įragment rightFragment = fragmentManager.findFragmentById(R.id.fragmentRight) If the right fragment does not exist, we need to start an activity to show the right fragment content.
So we need to change the code to check whether the right fragment exists or not. That action triggers a null pointer exception.
But the code needs to get the right fragment when the button is clicked.Because in the mobile layout file, there is only a left fragment, which does not contain the right fragment. But when you click the button on the mobile screen, the app stopped.You can see the youtube video for this step demo. Now run the MultipleFragmentActivity use mobile and a tablet emulator, you can find that the tablet screen is not changed but the mobile screen is changed more reasonably.large is just one layout qualifier, the layout file under layout-large folder will be used when android OS thinks the device screen size is large. To make the layout-large folder visible in android studio, you need to switch to Project mode in the left panel. And copy the original layout file to there, the layout file name does not change. Create a folder layout-large under app / src / main / res folder.Now the layout file only contains one left fragment. Modify app / res / layout / activity_multiple_fragment.xml file as below.To make the app load different layout files for multiple size screens, we need to follow the below steps.This layout file is ok for tablet devices with a big screen, but for mobile, it is not perfect. The above example’s activity layout file name is activity_multiple_fragment.xml, it is saved in the app/res/layout folder.If we run this example on a mobile phone, we will find a not user-friendly screen effect. Let’s see a previous example again Android Multiple Fragments In One Activity Example.When Android OS gets the device matched qualifier, it will use the resource files saved in that qualifier directory such as layout file, drawable file, etc. Qualifiers can be used for all android resources such as layout, drawable, mipmap, etc.
But how to make your single app show a different layout when running on different screen size devices? The answer is to use android qualifiers.But almost all mobile apps use a single panel model, because of it’s small screen size. This is because the tablet screen size is big, there is enough space to show content. If you use tablets often, you will find that most of the tablet apps use a two-panel model.