Two touches in ListView - Xamarim Forms

0

Is it possible to have ONE touch for a certain function (now I have to select an item using ItemTapped ) and TWO touches on the same ListView to do another function?

I did not get this information from Microsoft's website and from any other source.

My XAML:

<!-- ListView -->
                <ListView x:Name="lstCompra"  
                          BackgroundColor="Aqua"
                          SeparatorColor="DodgerBlue"
                          ItemTapped="Compra_OnItemTapped"
                          HasUnevenRows="True"
                          Margin="10, 0, 10, 10">
                          <!--  HasUnevenRows = Serve para fazer com que o conteúdo digitado não seja cortado -->
                    <ListView.ItemTemplate>
                        <!-- DataTemplate  = exibe dados de uma coleção de objetos em um ListView -->
                        <DataTemplate>
                            <ViewCell>
                                <Grid Margin="2">

                                    <!-- Linhas -->
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>

                                    <!-- Colunas -->
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>

                                    <!-- Código -->
                                    <StackLayout Grid.Row="0"
                                                     Grid.Column="0"
                                                     Orientation="Horizontal">
                                        <Label Text="S.C.:"
                                                   FontSize="Small"/>
                                        <Label Text="{Binding ID_SOLCOMPRA}" 
                                                   FontSize="Small"
                                                   TextColor="Black"/>
                                    </StackLayout>

                                    <!-- Data -->
                                    <StackLayout Grid.Row="0"
                                                     Grid.Column="1"
                                                     Orientation="Horizontal">
                                        <Label Text="Data:"
                                                   FontSize="Small"
                                                   HorizontalOptions="Start"/>
                                        <Label Text="{Binding DT_CADASTRO}" 
                                                   FontSize="Small"
                                                   TextColor="Black"
                                                   HorizontalOptions="Start"/>
                                    </StackLayout>

                                </Grid>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>

My C #:

//Selecionando item da lista
        private void Compra_OnItemTapped(object sender, ItemTappedEventArgs e)
        {
            solicita = (sender as ListView).SelectedItem as SolicitarCompra;
        }

I am trying to test what was passed to me by @AmadeuAntunes and I have not gotten it (I am very new to programming), it gives error on this line btnClick.Clicked + = (sender, e) = & gt ;.

The error:

OXAML:

<StackLayout><ButtonText="Teste"
                    Clicked="Btn_Teste"
                    x:Name="btnClick"/>
        </StackLayout>

The code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Teste
{
    public partial class MainPage : ContentPage
    {
        int ButtonCount = 0;

        public MainPage()
        {
            InitializeComponent();
        }

        void Btn_Teste(object sender, EventArgs e)
        {
            btnClick.Clicked += (sender, e) =>
            {

                if (ButtonCount < 1)
                {
                    TimeSpan tt = new TimeSpan(0, 0, 1);
                    Device.StartTimer(tt, TestHandleFunc);
                }
                ButtonCount++;
            };

            bool TestHandleFunc()
            {
                if (ButtonCount > 1)
                {
                    //Your action for Double Click here
                    DisplayAlert("", "Two Clicks", "OK");
                }
                else
                {
                    //Your action for Single Click here
                    DisplayAlert("", "One Click", "OK");
                }
                ButtonCount = 0;
                return false;
            }
        }
    }
}
    
asked by anonymous 27.06.2018 / 16:53

1 answer

0

I would use:

The first time you do ItemTapped it triggers a "timer" when it clicks again to stop the "timer" and calls another method that you can even call Cliqueduplo

  

1st TapGestureRecognizer - start a timer

     

2nd TapGestureRecognizer Stops the "timer" and invokes another method called doupleTapped

Something like this

     btnClick.Clicked += (sender, e) =>
                {
                    if (ButtonCount < 1)
                    {
                        TimeSpan tt = new TimeSpan(0, 0, 1);
                        Device.StartTimer(tt, TestHandleFunc);
                    }
                    ButtonCount++;
                };

bool TestHandleFunc()
        {
            if (ButtonCount > 1)
            {
            //Your action for Double Click here
                DisplayAlert("", "Two Clicks", "OK");
            }
            else
            {
            //Your action for Single Click here
                DisplayAlert("", "One Click", "OK");
            }
            ButtonCount = 0;
            return false;
        }
    
27.06.2018 / 17:02