Skip to content Skip to sidebar Skip to footer

Trouble In Hide/show Of Listview On A Click In Xamarin Android

Trying to show and hide(toggle) a listview on click of image in xamarin android using visual studio.But it doesnt hide.What am i doing wrong here. onclick i am not able to hide and

Solution 1:

This is wrong...

 ImageView ImageView = FindViewById<ImageView>(Resource.Id.imageView1);

 ImageView.FindViewById<ImageView>(Resource.Id.imageView1).Click += (object sender, System.EventArgs e) =>
 {
     listView.FindViewById<ListView>(Resource.Id.List).Visibility = Android.Views.ViewStates.Visible;
 };

You get the reference to the image view in the first line, but then do a FindViewById on that view to get a subview. Unless you have an ImageView nested inside of another ImageView, this isn't going to work.

You were close. This should work without seeing your layout...

ImageView imageView = FindViewById<ImageView>(Resource.Id.imageView1);

 imageView.Click += (object sender, System.EventArgs e) =>
 {
     if (listView.Visibility == ViewStates.Visible)
        listView.Visibility = ViewStates.Invisible;
     else
        listView.Visibility = ViewStates.Visible;
 };

FindViewById is an expensive call. Try not to make it over and over if you don't have to.

Post a Comment for "Trouble In Hide/show Of Listview On A Click In Xamarin Android"