I have 2 layouts and the fragment classes, one layout is what should appear when the screen is vertical, and the other is for when the screen is horizontal. How do I "inflate" one and "deflate" the other for when the screen rotation occurs and in which class do I boot the code? Will it stay like this?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view;
if (container != null) {
container.removeAllViewsInLayout();
}
int orientation = getActivity().getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
view = inflater.inflate(R.layout.activity_mainport, container, false);
} else {
view = inflater.inflate(R.layout.activity_mainland, container, false);
}
}
}