We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

(Android) SfListView selects row when tapping on buttons

Thread ID:

Created:

Updated:

Platform:

Replies:

130077 Apr 20,2017 04:42 AM UTC Mar 8,2018 01:03 PM UTC Xamarin.Forms 6
loading
Tags: SfListView
Ha
Asked On April 20, 2017 04:42 AM UTC

Hi,
When I put a control with tap gesture recognizer (or a button) inside a row and tap on that control, the row is also selected. It's not the expected behavior. This only occurs on Android (on iOS it runs normally).
I wonder if there's any workaround.

Dinesh Babu Yadav [Syncfusion]
Replied On April 23, 2017 01:22 PM UTC

Hi Customer, 
 
Apologies for the inconvenience caused. 
 
We have checked the reported query “ItemTapped event triggers while clicking the button in Android platform” at our end and we would like to let you know that, In Android platform when background color is set for SfListView, touch click listener is not passed to the SfListView due to some limitations in Xamarin Forms Android and the gestures like tapping, double tapping etc.., cannot be detected. So, 
we have internally override the OnInterceptTouchEvent(Implement this method to intercept all touch screen motion events) in the Android renderer project to detect the gestures event when background color is set. The OnInterceptTouchEvent is a Boolean type override method, if return false, the touch is passed to its child (example button within the ItemTemplate) and if returns true(default value), touch interaction is not passed to its child and the touch interaction is not detected if background color is set for SfListView. And we have deeply analyzed to provide a workaround regarding this but currently we are unable to achieve it in a sample level due to some limitations in Xamarin Forms. 
 
However, we will consider the reported query as feature enhancement and added into our feature request list. The feature will be available in our upcoming 2017 Volume 2 SP1 release and we will let you know once the release has been rolled out. We will appreciate your patience until then. 
 
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 


Eduardo
Replied On September 1, 2017 07:34 PM UTC

Hi,

has the feature been rolled out? Cause I'm experiencing the same sort of issue when SfListView is Horizontal. I have an image with tap gesture recognizer attached, when I tap the both events are fired, this is not the expected behavior. Is there any workaround?

Regards.


Dinesh Babu Yadav [Syncfusion]
Replied On September 4, 2017 11:43 AM UTC

Hi Eduardo, 
 
Sorry for the inconvenience. 
 
We regret to inform you that the reported feature enhancement could not able to include in our 2017 Volume 3 SP 1 release. Because, we are facing some Xamarin Framework hurdles while implementing it at our end. So, we will let you know once the enhancement has been completed and included in the release and we will appreciate your patience until then.   
 
However, you achieve the reported requirement by a workaround using TapGestureRecognizer in your View’s GestureRecognizer (Example: Grid’s GestureRecognizer) as like below code snippet and handle the tapped action for Android platform only. So, if the image in the template is tapped, only the gesture event for image gets triggered and similarly if the item is tapped, tap gesture’s tapped event will be triggered in which you can perform further process for tapped item as per your requirement. 
 
Code Example[XAML]: 
<sync:SfListView.ItemTemplate> 
  <DataTemplate> 
    <Grid> 
      <Grid.GestureRecognizers> 
        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/> 
      </Grid.GestureRecognizers> 
      <Grid RowSpacing="0" HorizontalOptions="Fill" VerticalOptions="Fill"> 
        <Image Source="{Binding PizzaImage}" HorizontalOptions="FillAndExpand" 
               VerticalOptions="FillAndExpand"> 
           <Image.GestureRecognizers> 
             <TapGestureRecognizer Tapped="ImageRecognizer_Tapped"/> 
           </Image.GestureRecognizers> 
        </Image> 
      <Label Grid.Row="1" Text="{Binding PizzaName}" 
             LineBreakMode="WordWrap" HorizontalTextAlignment="Center" 
             VerticalTextAlignment="Center" TextColor="#8f0100" 
             FontAttributes="Bold"/> 
      </Grid> 
    </Grid> 
  </DataTemplate> 
</sync:SfListView.ItemTemplate> 
 
Code Example[C#]: 
private void ListView_ItemTapped(object sender, ItemTappedEventArgs e) 
{ 
  if (Device.OS == TargetPlatform.Android) 
     e.Handled = true; 
} 
 
 
private void TapGestureRecognizer_Tapped(object sender, EventArgs e) 
{ 
   //Perform action for tapped item 
} 
 
private void ImageRecognizer_Tapped(object sender, EventArgs e) 
{ 
   //Perform action for image             
} 
 
For your reference, we have attached the sample and you can download it from the below link. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 
 


zahir yusuf khan
Replied On October 19, 2017 11:11 AM UTC

If I use the grids GestureRecognizer , how am I supposed to get the itemdata of the tapped item? 


Muthu Kumaran Gnanavinayagam [Syncfusion]
Replied On October 20, 2017 11:11 AM UTC

Hi Zahir, 

We have checked with the reported query “Need to get Grid data from its TapGestureRecognizer” from our side. You can get the item data from the BindingContext of that element in the Tapped event of the TapGestureRecognizer. Please refer the below code example. 

Code Example[XAML]: 
<sync:SfListView.ItemTemplate>  
  <DataTemplate>  
    <Grid>  
      <Grid.GestureRecognizers>  
        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>  
      </Grid.GestureRecognizers>  
      <Grid RowSpacing="0" HorizontalOptions="Fill" VerticalOptions="Fill">  
        <Image Source="{Binding PizzaImage}" HorizontalOptions="FillAndExpand"  
               VerticalOptions="FillAndExpand">  
        </Image>  
      <Label Grid.Row="1" Text="{Binding PizzaName}"  
             LineBreakMode="WordWrap" HorizontalTextAlignment="Center"  
             VerticalTextAlignment="Center" TextColor="#8f0100"  
             FontAttributes="Bold"/>  
      </Grid>  
    </Grid>  
  </DataTemplate>  
</sync:SfListView.ItemTemplate>  

Code Example[C#]: 
private void TapGestureRecognizer_Tapped(object sender, EventArgs e) 
{ 
  var grid = sender as Grid; 
  var pizzaInfo = grid.BindingContext as PizzaInfo; 
  App.Current.MainPage.DisplayAlert("GridData", "The name of the pizza is " + pizzaInfo.PizzaName, "Ok"); 
} 

For your reference, we have attached the sample link below. 


Please let us know if you require further assistance. 

Regards, 
G.Muthu Kumaran. 


Rawoof Sharief Muthuja Sherif [Syncfusion]
Replied On March 8, 2018 01:03 PM UTC

Hi Pri, 
 
As stated in the update dated on 4/23/2017 in this forum, we have explained the root cause for the reported issue and this was caused due to Xamarin Android behavior. However, we suggest you to refer the updates dated on 9/4/2017 and 10/20/2017 to achieve the reported requirement in which we have provided the samples too for your reference. 
 
Please let us know if you require further assistance. 
 
Regards, 
Rawoof M 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;