0

É possível ter UM toque para certa função (hoje tenho para selecionar um item utilizando ItemTapped) e DOIS toques no mesmo ListView para fazer outra função?

Não consegui essa informação no site da Microsoft e em nenhuma outra fonte.

Meu 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>

Meu C#:

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

Estou tentando testar o que me foi passado pelo @AmadeuAntunes e não tenho conseguido (sou bem novo na programação), dá erro nessa linha btnClick.Clicked += (sender, e) =>.

O erro:

inserir a descrição da imagem aqui

O XAML:

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

O código:

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;
            }
        }
    }
}
4
  • mostre o código 27/06/2018 às 15:02
  • Adicionado o código @LeandroAngelo 27/06/2018 às 15:46
  • Você está aprendendo ou trabalhando com Xamarim?
    – Marconi
    28/06/2018 às 17:17
  • Os dois, estou aprendendo no trabalho rs. A minha prática tem sido num app real. 28/06/2018 às 17:22

1 Resposta 1

0

Eu usaria:

Da primeira vez que faz ItemTapped acciona um "timer" quando voltar a clicar novamente pára o "timer" e chama outro método que até pode chamar de Cliqueduplo

1º TapGestureRecognizer - começar um "timer"

2º TapGestureRecognizer Pára o "timer" e invoca outro método chamado doupleTapped

Algo assim

     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;
        }
2
  • Adicionado o retorno do teste na minha postagem, se puder conferir agradeço. 28/06/2018 às 17:19
  • Dessa forma não parece ser a melhor opção depois de termos visto sobre o TapGesture aqui na empresa, estamos tentando adaptá-lo no sistema. Mas agradeço pela opção colocada. 11/07/2018 às 17:54

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .