I have an activity with a relative layout; And have two different fragments. I show one fragment and switch to the next fragment on a button click vice verse.
// When button menu is clicked
OnClickListener btnClick = new OnClickListener() {
@Override
public void onClick(View arg0) {
if(currentType==0){
InitThisFragment(1);
}else{
InitThisFragment(0);
}
}
};
public void InitThisFragment(int type){
Fragment newFragment;
if(type==0){
newFragment=new MainFragment();
}else{
newFragment=new JourneyFragment();
}
currentType=type;
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.abs_fragment_container, newFragment);
transaction.addToBackStack(null);
transaction.commit();
}
R.id.abs_fragment_container is a Relative Layout
BOTH THE FRAGMENT CONTAIN GOOGLE MAPS INSIDE THEM;
But it is not working as expected.
- By default i add the first fragment [which works fine].
- Then after an onClick event the 2nd fragment comes[which also works fine]
- But on my next click the app crashes;
Please help I am new to Google Maps and Fragments;