How to string phone number to call function Xamarin?

Mila

I use this code for calling in Xamarin.

enter code here var phoneDialer = CrossMessaging.Current.PhoneDialer;
        if (phoneDialer.CanMakePhoneCall)
            phoneDialer.MakePhoneCall("?");

I have list with contacts. I want that, if I click på phone number, then it is calling direct to person I want. If I write some number in ? place, function works, but phone number is the same for all contacts. What I need to write in ? place, at that find and change number, if I click on another person?

This is my kontaktlist:

   public partial class Kontaktliste : ContentPage
{
    KontaktlisteView vm;

    public int Tlfnr { get; private set; }

    public Kontaktliste()
    {
        InitializeComponent();
        vm = new KontaktlisteView();
        NameslistView.ItemsSource = vm.Kontakter;

        //Order the contacts
        var sorted = vm.Kontakter.OrderBy(x => x.Fødselsdage)
                              .ToList();

        //Set the ItemsSource with the ordered contacts
        NameslistView.ItemsSource = sorted;
    }

    private async void Kontakter_ItemTapped(object sender, ItemTappedEventArgs e)
    {
        ((ListView)sender).SelectedItem = null;
        var Kontakter = e.Item as Kontakter;

        await DisplayAlert("Kontakt", "\nName: " + Kontakter.Fuldenavn + "\nTelefon: " + Kontakter.Tlfnr + "\nEmail: " + Kontakter.Email + "\nAdresse: " + Kontakter.Adresse + "\nFødselsdage: " + Kontakter.Fødselsdage, "Luk");
    }
    //Search button
    private void MainSearchBar_SearchButtonPressed(object sender, EventArgs e)
    {
        var keyword = MainSearchBar.Text;
        NameslistView.ItemsSource = vm.Kontakter.Where(obj => (obj.Fuldenavn.Contains(keyword) || obj.Tlfnr.ToString().Contains(keyword)));
    }
    private void MainSearchBar_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (e.NewTextValue == string.Empty)
        {
            NameslistView.ItemsSource = vm.Kontakter.Where(name => (name.Fuldenavn.Contains("")));
        }
    }

    //Ring når klikke på telefon nummer





    public void OnTelefonTapped(object sender, EventArgs e)
    {

        var phoneDialer = CrossMessaging.Current.PhoneDialer;
        if (phoneDialer.CanMakePhoneCall)
            phoneDialer.MakePhoneCall("");

    }

and contacts

 public class Kontakter
{
    public static List<Kontakter> ItemsSource { get; internal set; }
    public string Fuldenavn { get; set; }
    public int Tlfnr { get; set; }
    public string Email { get; set; }
    public string Adresse { get; set; }
    public string Billed { get; set; }
    public DateTime Fødselsdage { get; set; }

    public List<Kontakter> GetKontakter()
    {
        List<Kontakter> kontakter = new List<Kontakter>()
        {
            new Kontakter ()
            {
                Fuldenavn = Name,
                Tlfnr =1234567
                Email = [email protected]
                Adresse = 
                Billed = 
                Fødselsdage=new DateTime()

            },

And

<ScrollView>
    <StackLayout>
        <SearchBar x:Name="MainSearchBar" Placeholder="Søg" SearchButtonPressed="MainSearchBar_SearchButtonPressed"  TextChanged="MainSearchBar_TextChanged"/>
        <ListView x:Name="NameslistView" HasUnevenRows="True" ItemTapped="Kontakter_ItemTapped" 
            ItemsSource="{Binding Kontakter}" >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Vertical" >
                            <Grid HeightRequest="5" BackgroundColor="White"  />
                            <StackLayout Orientation="Horizontal" BackgroundColor="LightSkyBlue" >
                                <Image Source="{Binding Billed}" />
                                <StackLayout Orientation="Vertical">
                                    <Label Text="{Binding Fuldenavn}" TextColor="Black" FontSize="Large" />
                                    <StackLayout>
                                        <Label Text="{Binding Tlfnr}" TextColor="Black" FontSize="Medium"/>
                                        <Label.GestureRecognizers>
                                            <TapGestureRecognizer

                                                 Tapped="OnTelefonTapped">
                                            </TapGestureRecognizer>
                                        </Label.GestureRecognizers>
                                    </StackLayout>
                                    <StackLayout>

                                        <Label Text="{Binding Email}" TextColor="Black" FontSize="15"></Label>
                                        <Label.GestureRecognizers>
                                            <TapGestureRecognizer

                                                 Tapped="OnEmailTapped">
                                            </TapGestureRecognizer>
                                        </Label.GestureRecognizers>
                                    </StackLayout>
                                </StackLayout>
                            </StackLayout>
                        </StackLayout >
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout >

</ScrollView>

Jason

since your TapGestureRecognizer is attached to a Label, you should be able to do this

public void OnTelefonTapped(object sender, EventArgs e)
{
    var source = (Label)sender;
    var phone = source.Text;

    var phoneDialer = CrossMessaging.Current.PhoneDialer;
    if (phoneDialer.CanMakePhoneCall)
        phoneDialer.MakePhoneCall(phone);

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add Call a phone number link in innerHTML

From Dev

How to call a phone number from ios app?

From Dev

How to add Call a phone number link in innerHTML

From Dev

How to call method by string name in Windows Phone

From Dev

How to call method by string name in Windows Phone

From Dev

How to call a Function with a RETURN NUMBER

From Dev

How to mask a string that contains phone number in Oracle?

From Dev

How to make a phone call in Xamarin.Forms by clicking on a label?

From Dev

Call a function if String number is inferior to 0?

From Dev

How to call a number from another function into a function?

From Dev

How to count the number of dashes (-) in a phone number String for input validation?

From Dev

How to call a function on string jQuery

From Dev

How to call a function defined as a string?

From Dev

How to call a method or phone number using notifcation addAction

From Dev

how to call a phone number through javascript without using <a> tag?

From Dev

How to intercept a phone number click (Call button) on link in UITextView?

From Dev

Android How to Call a phone number using CardView OnClick method

From Dev

How to call a PSTN number from a soft SIP Phone through Asterisk

From Dev

How to write a phone number for calling in android but not make the call

From Dev

How to call phone number ending with # using Android Dialer

From Dev

How to receive number when Twilio make a phone call?

From Dev

Identify phone number in a string

From Dev

Make a phone call to number containing "#"

From Dev

How to limit the number of failed attempts to call a function?

From Dev

How to call index number of function array in javascript

From Dev

how to create call function in windows phone 8 app?

From Java

How to create a custom order to sort Java String phone number?

From Dev

How to create a custom order to sort Java String phone number?

From Dev

phone number validation in check_phone function

Related Related

  1. 1

    How to add Call a phone number link in innerHTML

  2. 2

    How to call a phone number from ios app?

  3. 3

    How to add Call a phone number link in innerHTML

  4. 4

    How to call method by string name in Windows Phone

  5. 5

    How to call method by string name in Windows Phone

  6. 6

    How to call a Function with a RETURN NUMBER

  7. 7

    How to mask a string that contains phone number in Oracle?

  8. 8

    How to make a phone call in Xamarin.Forms by clicking on a label?

  9. 9

    Call a function if String number is inferior to 0?

  10. 10

    How to call a number from another function into a function?

  11. 11

    How to count the number of dashes (-) in a phone number String for input validation?

  12. 12

    How to call a function on string jQuery

  13. 13

    How to call a function defined as a string?

  14. 14

    How to call a method or phone number using notifcation addAction

  15. 15

    how to call a phone number through javascript without using <a> tag?

  16. 16

    How to intercept a phone number click (Call button) on link in UITextView?

  17. 17

    Android How to Call a phone number using CardView OnClick method

  18. 18

    How to call a PSTN number from a soft SIP Phone through Asterisk

  19. 19

    How to write a phone number for calling in android but not make the call

  20. 20

    How to call phone number ending with # using Android Dialer

  21. 21

    How to receive number when Twilio make a phone call?

  22. 22

    Identify phone number in a string

  23. 23

    Make a phone call to number containing "#"

  24. 24

    How to limit the number of failed attempts to call a function?

  25. 25

    How to call index number of function array in javascript

  26. 26

    how to create call function in windows phone 8 app?

  27. 27

    How to create a custom order to sort Java String phone number?

  28. 28

    How to create a custom order to sort Java String phone number?

  29. 29

    phone number validation in check_phone function

HotTag

Archive