Jump to content
Android Forum - A Community For Android Users and Enthusiasts

fragment side by side


piggybank1974
 Share

Recommended Posts

what I'm trying to do is in portrait mode display a fragment, in landscape mode display two fragments side by side.

 

it all seems to work fine until I rotate the emulator from landscape to portrait then the app crashes with this:

 

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fragmentapp/com.fragmentapp.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002

 

it all works fine if I put the fragments in the XML but I'm trying to call them programically with this:

 

 

@Override

protected void onCreate(Bundle savedInstanceState)

{

FragmentTransaction mft = getFragmentManager().beginTransaction();

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

 

FragmentOne mFragmentOne = new FragmentOne();

//getFragmentManager().beginTransaction().add(R.id.container, mFragmentOne).commit();

mft.add(R.id.leftfragment, mFragmentOne);

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)

{

FragmentTwo mFragmentTwo = new FragmentTwo();

mft.add(R.id.rightfragment, mFragmentTwo);

//getFragmentManager().beginTransaction().add(R.id.container, mFragmentTwo).commit();

}

else

{

FrameLayout FragmentContainer = (FrameLayout) findViewById(R.id.rightfragment);

if (FragmentContainer != null)

{

getFragmentManager().beginTransaction().remove(new FragmentTwo()).commit();

}

 

}

mft.addToBackStack(null);

mft.commit();

}

 

I do have fragmentone.xml in layout folder where I have fragmetone.xml/fragmenttwo.xml in layout-land folder if this helps??

 

any body got any ideas!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...