Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Button in ListView blocks ItemSelected in Android

$
0
0

I have a ListView with a label and a button in each cell. I install an ItemSelected handler, but the handler never gets called (on Android). No matter where I touch on the list item the item will not get selected. On iOS this works fine. If I remove the button, so the cell contains only the label, the item selected gets hit correctly.

` List stringList = new List () { "abc", "xyz", "todo" };

        _listView = new ListView ();
        _listView.ItemsSource = stringList;

        _listView.ItemTemplate = new DataTemplate(() =>
            {
                var label = new Label();
                label.SetBinding(Label.TextProperty, ".");

                var button = new Button() { Text = "Test" };

                return new ViewCell
                {
                    View = new StackLayout
                    {
                        Padding = new Thickness(0, 5),
                        Orientation = StackOrientation.Horizontal,
                        Children =  { label, button }
                    }
                };
            });


        var resultLabel = new Label() { Text = "A" };
        _listView.ItemSelected += (sender, args) =>
        {
            resultLabel.Text = resultLabel.Text + "!";
            //Navigation.PushAsync(new OtherPage());
        };


        var layout = new StackLayout () {
            Orientation = StackOrientation.Vertical,
            Children = { _listView, resultLabel }
        };

        Content = layout;`

Known issue? Should I file a bug report?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>