Im like doing this to a imageView i have in my adapter
pokemon.Click += clicker;
( i passed clicker through parameter to the adapter as an EventHandler )
and in my main activity i have the
public void clicker(object obj,EventArgs args){ ((View)obj).FindViewById<ImageView> (Resource.Id.pokemon).Visibility = ViewStates.Invisible; }
but i need to change the visibility of another imageView that is in my parameter it is named digimon, but if i do this
public void clicker(object obj,EventArgs args){ ((View)obj).FindViewById<ImageView> (Resource.Id.pokemon).Visibility = ViewStates.Invisible; ((View)obj).FindViewById<ImageView> (Resource.Id.digimon).Visibility = ViewStates.Invisible; }
i get "Object reference not set to an instance of an object"
How can i reach that second image? help please
Posts
obj
is theImageView
, so you need to drill upwards in theView
hierarchy to get the parent of the otherImageView
.Imagine the hierarchy is like this:
Now when using
This should work fine, because
obj
is already theImageView
you attached theclicker
event to. In this casepokemon
. So you could just do:((ImageView)obj).Visibility = ...
.If you want to find
digimon
in there as well you will need to do something like:This will get you the root of the hierarchy, which in this case is the
LinearLayout
and on that callFindViewById<ImageView>(Resource.Id.digimon)
.However, I prefer just to do it on the
contentView
instead and simply callFindViewById<ViewType>()
on it rather than doing it on the object passed to the EventHandler.Wokred fine, but how can i use this contentView?
It is what you set at the beginning of your
Activity
'sOnCreate
method, withSetContentView
. Then that should be available in yourActivity
by simply callingFindViewById()
.