[mono-android] FindViewById returning a ViewGroupInvoker
djtails at gmx.net
Thu Feb 23 00:37:17 UTC 2012
It fails because you need the Activity Context for the FindViewByID
and some Layout has not the Context to work with it.
Would be my answer to this.
Am 22.02.2012 um 20:07 schrieb Chris Tacke:
> 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.
>> -----Original Message-----
>> From: monodroid-bounces at lists.ximian.com [mailto:monodroid-
>> bounces at 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,
>> And the MapView shows up on the screen and works just fine.
>> The MapView is defined in the layout like this:
>> android:apiKey="mykey" />
>> Later on in my app, I'd like to get hold of this MapView so I can
>> in on it, but I'm having difficulty.
>> My first attempt returned null:
>> var m =
>> 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
>> 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
>> 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
>> 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.
>> Monodroid mailing list
>> Monodroid at lists.ximian.com
>> UNSUBSCRIBE INFORMATION:
> Monodroid mailing list
> Monodroid at lists.ximian.com
> UNSUBSCRIBE INFORMATION:
More information about the Monodroid