piggybank1974
Lurker
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:
[HIGH]
@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();
}
[/HIGH]
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!
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:
[HIGH]
@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();
}
[/HIGH]
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!