I am trying to add small maps to a list and have created a Cursor adapter to handle a list of locations.
The layout for the individual location looks like this:
<LinearLayout
... >
<TextView android:id="@+id/start_loc"
...
/>
<fragment android:id="@+id/start_loc_map"
android:name="com.google.android.gms.maps.MapFragment"
...
/>
</LinearLayout>
Then in the adapter:
@Override
public void bindView(View view, Context context, Cursor cursor) {
startLocView = (TextView) view.findViewById(R.id.start_loc);
then something like:
SupportMapFragment startLocMap =
(SupportMapFragment) view.findViewById(R.id.start_loc_map);
or:
SupportMapFragment startLocMap =
(SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.start_loc_map);
Neither of these works. The view (not surprisingly) can't be cast as a fragment and there is no fragment or activity available to the adapter. I can get a Context and (Activity) context.getFragmentManager
but I can't find any way to get to getChildFragmentManager
from that. I can get a FrameLayout, which is what the container object is but I don't know any way to reference to the Fragment contained therein.
How do I get a reference to a static (?) fragment in a layout from an adapter? Is getting a <fragment>
less straightforward than a <TextView>
?