Pergunta

What I'm trying to do is have a master/detail style app where one of my selector options is a Google Map with some extra buttons below the map layout.

All my other options just load a Fragment into a FrameLayout, using something like:

getSupportFragmentManager().beginTransaction()
    .replace(R.id.content, myFragment, fragTag)
    .commit();

I can't do that with the MapFragment because I need other things in the layout and nested Fragments aren't supported (yet hopefully). So, I need to replace a regular Fragment with a composite view that contains a Fragment, but I'm not sure how the Fragment management should work here.

I don't think I can just call

getSupportFragmentManager().beginTransaction()
    .replace(R.id.content, myCompositeView, fragTag)
    .commit();

At the moment I'm doing this:

Fragment currentFrag = getSupportFragmentManager().findFragmentById(R.id.content); 
getSupportFragmentManager().beginTransaction().remove(currentFrag);

LayoutInflater inflator = LayoutInflater.from(this);
ViewGroup container = (ViewGroup)findViewById(R.id.content);
container.removeAllViews();

View mapView = inflator.inflate(R.layout.store_finder, container, true);

It makes it a bit messy when replacing this with other fragments again as I need to remove all the views from the layout again. Also, I'm not sure how to properly remove the MapFragment after setting it up like this.

I'd appreciate any help and for someone to put my mind at rest :)

Footnote: Apparently Nested Fragments are a thing now, but not sure this is the way I want to go for something simple. http://developer.android.com/about/versions/android-4.2.html#NestedFragments

Foi útil?

Solução

Nested Fragments are suppported, please see:

http://developer.android.com/reference/android/app/Fragment.html#getChildFragmentManager()

I'm using them in a current app / project and they work great. Not sure if there is any additional constraint with using them with your mapping view?

// WildStyle

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top