I have an activity in fragment with three bottom navigation tabs. Each having two xml files for portrait and landscape. Whenever I change the orientation layout used to show appropriate xml files but was restarting activity.
So in manifest file I included
android:configChanges="orientation|screenSize"
After this change, activity is not restarting but on orientation change layout is not picking appropriate xml files. ie when change from portrait to landscape view is showing portrait file not picking up landscape xml file.
Below is my code for inflating view from fragment.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_data_monitor, container, false);
return view;
}
Any help would be appreciated.
Do like this,
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_data_monitor, container, false);
initUI(); // Define all your xml attributes, like, EditText, Button etc
return view;
}
and use one more method, ie onConfigurationChanged();
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRetainInstance(true);
initUI(); // Call this again.
}
Hope this will help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.