I am implementing the registration/login part of an application and I am trying to implement it in one activity by using different fragments for login and signup.
I have two different layouts for portrait and landscape mode, which are basically a vertical layout for the portrait one and a horizontal layout for landscape, both with a logo and a FrameLayout containing the fragment (let's consider ony the login one).
The fragment is inflated by an xml resource file and inserted programmatically in the activity onCreate() method in this way:
fragmentManager = this.getFragmentManager();
ViewGroup root = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
LinearLayout linearLayout = (LinearLayout) root.getChildAt(0);
frameLayout = (FrameLayout) linearLayout.getChildAt(1);
loginFragment = (LoginFragment) fragmentManager.findFragmentByTag("loginFragment");
if (loginFragment == null) {
// If fragment wasn't saved, create new one
Log.d("DEBUG", "Fragment is null");
loginFragment = new LoginFragment();
}
else
Log.d("DEBUG", "Fragment is not null");
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(frameLayout.getId(), loginFragment, "loginFragment");
transaction.commit();
Everything works fine until I rotate the screen, then I get the following:
java.lang.IllegalStateException: Can't change container ID of fragment LoginFragment{19d136ec #0 id=0x7f090040 loginFragment}: was 2131296320 now 2131296322
I tried to place fragmentManager.executePendingTransactions();
after the commits, but still the same problem. I really don't know what more to try, hope to get some hints.
0 comments:
Post a Comment