Bug 22910 - LV.ItemSelected does not works twice (same item)
Summary: LV.ItemSelected does not works twice (same item)
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-09-12 05:53 UTC by Fredy Wenger
Modified: 2017-10-29 05:29 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Fredy Wenger 2014-09-12 05:53:00 UTC
The Lisview.ItemSelected-event cannot be used twice for the same item.
Often a ListView is used to show some collected data form a query or as "Menu".
If an item is selected and the listview is showed again, the last selected item is highlighted (what is correct), but the user cannot the same item once again without select another item first.
Bug:
=> The .ItemSelected-event does nor fire, if the same item is selected twice (without that an another item is selected between). 

So.. the ListView is not usable without implement an workaround (clear the selected Item) TO ANY ListView in the app :
ListView.ClearValue(ListView.SelectedItemProperty);

This is very annoying (for me it's a major bug!) and DON'T WORK IN ANY Case.
Comment 1 Sadik Ali 2014-09-12 07:22:19 UTC
I have checked this issue and I am able to reproduce this issue.

Steps to reproduce:

1. Open the "Xamarin.Forms.Portable" app in VS 2013.
2. Add a new XAML page on portable project.
3. Write the following code in constructor of newly added class.
    
      var listView = new ListView { RowHeight = 40
            };

            listView.ItemsSource = new string [] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

            listView.ItemSelected += (sender, e) => { 
                DisplayAlert("This is Alert","Selected Item : "+e.SelectedItem,"Ok","Cancel");
            };

            Content = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children = {listView} };

4. Call the above class from App.cs.
5. Build and debug the project.

Observations: When I select the list view item second time, I observed that list view "ItemSelected" event is not fired for second time. If I click on next item it is working fine but only for first time and again click back on previous one then it call the "ItemSelected" event but it doesn't call the same event when I click on it second time.

Screencast: http://www.screencast.com/t/GssyyCLzwx
Build output: https://gist.github.com/anonymous/80dac77087776dc81499
ADB logcat: https://gist.github.com/saurabh360/5a57799f7d3fef8d31b4

Environment Info:

Xamarin.Forms: 1.2.2.6243

Windows  Info:

Windows 7
Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.50938
Installed Version: Professional
Xamarin   3.5.55.0 (2db5ccd228887372e207e112bc3b5f1b16b24293)

Mac Info

Mac OS X 10.9.3
Mono 3.8.0 ((no/45d0ba1)
Xcode 5.1 (5084)
Xamarin.iOS : 7.4.0.108 (Enterprise Edition)
Comment 2 Eric Maupin 2014-09-12 18:34:21 UTC
This is the intended behavior. The item remains selected, tapping it again does not change the item selection. `ItemTapped` is probably the event you're looking for.
Comment 3 Fredy Wenger 2014-09-15 03:53:53 UTC
I have seen the ItemTapped-Event myselve in the meantime and am on the way, to check it out.
If it works in any case, your are right - then the Problem is solved für me.
Fredy
Comment 4 Mohammed Rauff 2017-10-29 05:28:07 UTC
This bug is solved by me, just follow the below steps as i did.

1. First of all we need to navigate to other page whne we tapped or selected an item in list view right, so see this, here i need to navigate to nIvegPage from Home page's list view.
here is the code:

 private  void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
        {

            var item = (RecipesViewModel)e.SelectedItem;
            if (item == null) { return; }

            NavigationPage page = null;

            switch (item.RecipeName)
            {
                case "North Indian Vegetarian Recipes":
                    page = new 
        NavigationPage((Page)Activator.CreateInstance(typeof(nIVegRecipe)));
                   
                    break;
                case "South Indian Vegetarian Recipes":
                   NavigationPage((Page)Activator.CreateInstance(typeof(sIVegRecipe)));
                    break;
                case "West Indian Vegetarian Recipes":
                   NavigationPage((Page)Activator.CreateInstance(typeof(wIVegRecipe)));
                    break;
                

                default:
                   // page = new ExamplePage();
                    break;
            }

            page.BindingContext = item;
             Navigation.PushAsync(page);
            lstView.SelectedItem = null;
            ((ListView)sender).SelectedItem = null;
            

        }


2. So finally use navigation page instead of using content page and also use
             lstView.SelectedItem = null;
            ((ListView)sender).SelectedItem = null;
in order to deselect the previously selected Item in the list view. That's all issue solved. Thanks to all Xamarin Forms Developers.
Comment 5 Mohammed Rauff 2017-10-29 05:29:37 UTC
This bug is solved by me, just follow the below steps as i did.

1. First of all we need to navigate to other page whne we tapped or selected an item in list view right, so see this, here i need to navigate to nIvegPage from Home page's list view.
here is the code:

 private  void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
        {

            var item = (RecipesViewModel)e.SelectedItem;
            if (item == null) { return; }

            NavigationPage page = null;

            switch (item.RecipeName)
            {
                case "North Indian Vegetarian Recipes":
                    page = new 
        NavigationPage((Page)Activator.CreateInstance(typeof(nIVegRecipe)));
                   
                    break;
                case "South Indian Vegetarian Recipes":
                   NavigationPage((Page)Activator.CreateInstance(typeof(sIVegRecipe)));
                    break;
                case "West Indian Vegetarian Recipes":
                   NavigationPage((Page)Activator.CreateInstance(typeof(wIVegRecipe)));
                    break;
                

                default:
                   NavigationPage((Page)Activator.CreateInstance(typeof(NewPage)));
                    break;
            }

            page.BindingContext = item;
             Navigation.PushAsync(page);
            lstView.SelectedItem = null;
            ((ListView)sender).SelectedItem = null;
            

        }


2. So finally use navigation page instead of using content page and also use
             lstView.SelectedItem = null;
            ((ListView)sender).SelectedItem = null;
in order to deselect the previously selected Item in the list view. That's all issue solved. Thanks to all Xamarin Forms Developers.