Listview itemtapped not working if there is any button or any event control inside in android

anirbandebroy.5119anirbandebroy.5119 USMember ✭✭
edited May 17 in Xamarin.Forms

Listview itemtapped not working if there is any button or any event control inside.Any help is highly helpful. Thanks is advance.

<ListView ItemsSource="{Binding ListCheckBox}"
                                  ItemTapped="FlowListView_FlowItemTapped"
                                  SeparatorVisibility="None" 
                                  RowHeight="120"
                                  HasUnevenRows="True"
                                  HorizontalOptions="Center"
                                  VerticalOptions="Center"
                                  SeparatorColor="Transparent"
                                  BackgroundColor="Transparent"
                                                      >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                    <StackLayout Spacing="0">
                        <ctlr:TestView MenuTitle="{Binding MenuTitle}"
                                                           IsToggled="{Binding IsToggled, Mode=TwoWay}" 
                                                           SelectOptionValue="{Binding SelectOptionValue,Mode=TwoWay}"
                                                           Margin="0,5,0,20"/>
                        <Editor x:Name="TxtComment" HeightRequest="70" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Placeholder="What is your action?"   TextColor="#58595B" IsVisible="{Binding IsCommentBoxVisible}" Text="{Binding Comment}" BackgroundColor="White" FontSize="Small"/>
                    </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

//Code for the view
<ContentView.Content>
       <Grid Margin="0,5,0,0">
           <Grid.RowDefinitions>
               <RowDefinition Height="Auto"/>
               <RowDefinition Height="Auto"/>
               <RowDefinition Height="Auto"/>
           </Grid.RowDefinitions>
           <Grid.ColumnDefinitions>
               <ColumnDefinition Width="60*"/>
               <ColumnDefinition Width="40*"/>
           </Grid.ColumnDefinitions>
           <Label Text="{Binding MenuTitle}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"/>
           <control:SegmentedControl 
               Grid.Row="1"
               Grid.Column="0"
               x:Name="SegmentedControl" 
               TintColor="#00a2db"
               SelectedTextColor="White"
               DisabledColor="Gray"
               SelectedSegment="{Binding SelectOptionValue,Mode=TwoWay}">
               <control:SegmentedControl.Children>
                   <control:SegmentedControlOption Text="Safe"/>
                   <control:SegmentedControlOption Text="Unsafe"/>
                   <control:SegmentedControlOption Text="N/A"/>
               </control:SegmentedControl.Children>
           </control:SegmentedControl>
           <flex:FlexButton
                   Grid.Row="1"
                   Grid.Column="1"
                   HorizontalOptions="Center"
                   CornerRadius="5"
                   BorderColor="Gray"
                   HighlightBorderColor="#00a2db"
                   Text="Feedback Given"
                   ToggleMode="true"
                   FontSize="10"
                   IsToggled="{Binding IsToggled}"
                   ForegroundColor="Black"
                   HighlightForegroundColor="#ffffff"
                   BackgroundColor="#ededed"
                   HighlightBackgroundColor="#00a2db"/>
           <Button Text="Try me"  Grid.Row="2"
                   Grid.Column="0" Grid.ColumnSpan="2" />
       </Grid>
   </ContentView.Content>

If i use button also same issue is reproducible easily.One main point the issue i observed in android only did not tested IOS till now.

Expected behavior
The Itemtapped event should fire

Basic Information
Xamarin forms : 3.4.0.1008975 and below upto 3.1
Platform: Android

Answers

  • anirbandebroy.5119anirbandebroy.5119 USMember ✭✭
    edited May 17

    Sample Application for the reproduction

  • Sumit_SharmaSumit_Sharma USMember ✭✭✭

    It is working

    I am using VS2019.

    Try to clean close rebuild run the solution

  • Sumit_SharmaSumit_Sharma USMember ✭✭✭

    I believe this depends upon where you click, if you click on any other place except where there is not another tapped/pressed event, ItemTapped will be fired.

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited May 28

    @anirbandebroy.5119
    I reproduced you code and change it as follows. It works every time I click it.

    private void FlowListView_FlowItemTapped(object sender, ItemTappedEventArgs e)
    {
        //var item = ((TestViewViewModel)((DLToolkit.Forms.Controls.FlowListView)sender).FlowLastTappedItem);
    
        //item.IsCommentBoxVisible = item.SelectOptionValue == 1 ? true : false;
        Console.WriteLine("====FlowListView_FlowItemTapped====");
    }
    

    Check you code in Tapped event.

        var item = ((TestViewViewModel)((DLToolkit.Forms.Controls.FlowListView)sender).FlowLastTappedItem);
    
        item.IsCommentBoxVisible = item.SelectOptionValue == 1 ? true : false;
    
  • Sumit_SharmaSumit_Sharma USMember ✭✭✭

    And your sender is ListView not FlowListView, how can you typecast in FlowListView???

  • anirbandebroy.5119anirbandebroy.5119 USMember ✭✭
    edited May 17

    @yelinzh @Sumit_Sharma sorry earlier i was using flowlistview so it is still there. but my issue was when i am tapping on top of button or the segment control it was not working.In sort if I tapped on any button it was not working but if i am tapping on any label it was working fine.

    So is there anyway to do it ? As on tap of any button i have to carry out some operation ,As currently it was not firing because of that i am facing the above issue.

  • Sumit_SharmaSumit_Sharma USMember ✭✭✭

    If you want to perform on Button Click --> Add Event in your button and perform it.

    But I would request you to learn MVVM and bind button with a command from ViewModal, and perform your functionality over there.

  • anirbandebroy.5119anirbandebroy.5119 USMember ✭✭
    edited May 17

    @Sumit_Sharma I am completely aware of event and command binding but here my main issue was performing a specific operation on specific segment click.so I will try a work around but i believe if i am clicking on any control inside a listview the ItemTappedEvent should fire which is not happening here.If this is my code problem it is ok but if xamarin does not support this then it is a issue and none of my inside control has any events which might cause the event bubbling problems.

  • Sumit_SharmaSumit_Sharma USMember ✭✭✭

    i am clicking on any control inside a listview the ItemTappedEvent should fire which is not happening here

    It doesn't happen.

    Please clarify this for me, if you have a enable button inside listview and you want to perform some specific action on button click only.

    How will the operating system(your mobile device) knows which event to fire????? (i.e. Button Click or List Item Tapped)

    Now if you disable your button and then click on Button, your Item Tapped event will be fired.

    if xamarin does not support this then it is a issue and none of my inside control has any events which might cause the event bubbling problems.

    I believe @yelinzh would be better person to explain this!

Sign In or Register to comment.