Reputation: 11
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. i.e 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.
Upvotes: 0
Views: 483
Reputation: 2780
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, i.e. onConfigurationChanged();
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRetainInstance(true);
initUI(); // Call this again.
}
Hope this will help.
Upvotes: 0