In the end it worked if I requested the FindViewById from the Activity itself, not the Layout:
This fails: var map = m_layout.FindViewById<MapView>(Resource.Id.DriverMap); This works: var map = this.FindViewById<MapView>(Resource.Id.DriverMap); So that answers #1. But #2 is still apropos. Why does the first case above fail? The MapView *is* in that Layout. -Chris > -----Original Message----- > From: monodroid-boun...@lists.ximian.com [mailto:monodroid- > boun...@lists.ximian.com] On Behalf Of Chris Tacke > Sent: Wednesday, February 22, 2012 9:50 AM > To: Discussions related to Mono for Android > Subject: [mono-android] FindViewById returning a ViewGroupInvoker > > I have an AbsoluteLayout that contains a MapView. I load this layout > in my Activity (which is a MapActivity) like this: > > m_layout = LayoutInflater.Inflate(Resource.Layout.DriverLayout, null); > SetContentView(m_layout); > > And the MapView shows up on the screen and works just fine. > > The MapView is defined in the layout like this: > > <com.google.android.maps.MapView > android:id="@+id/DriverMap" > android:layout_width="800px" > android:layout_height="400px" > android:layout_x="0px" > android:layout_y="100px" > android:clickable="true" > android:apiKey="mykey" /> > > Later on in my app, I'd like to get hold of this MapView so I can zoom > in on it, but I'm having difficulty. > > My first attempt returned null: > > var m = > m_layout.FindViewById<MapView>(Resource.Id.DriverMap); > > A more generic version with a cast fails (i.e. code doesn't continue to > run past this point - assuming the cast failed) > > var m = (MapView)m_layout.FindViewById (Resource.Id.DriverMap); > > So I tried without a cast: > > var m = m_layout.FindViewById (Resource.Id.DriverMap) as > Android.GoogleMaps.MapView; > > And again I get back a null; > > So I tried this: > var m = m_layout.FindViewById(Resource.Id.DriverMap); > > And I *do* get back an object - just not a MapView. I run this: > > var mt = m.GetType().Name; > > And I get back "ViewGroupInvoker" > > My GoogleFu fails to even find what this type is. Obviously it's > related to a ViewGroup, but I've not explicitly created one (maybe the > MapView does?). So I guess I have a couple questions: > > 1. How do I get access to my MapView? I mean that's really what I > want. > 2. Why am I getting back this "ViewGroupInvoker" and what is it? > Getting the right answer (#1) is good, but understanding the failure is > also important so I don't fall into this again. > > -Chris > > > _______________________________________________ > Monodroid mailing list > Monodroid@lists.ximian.com > > UNSUBSCRIBE INFORMATION: > http://lists.ximian.com/mailman/listinfo/monodroid _______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid