Put item in Label from firebase

BorisopritBorisoprit Member ✭✭✭
edited January 11 in Xamarin.Forms

With this i fill a Listview from a Firebase database with Name

`

protected async override void OnAppearing()
{
await Task.Delay(2000);

        base.OnAppearing();
        var allPersons = await firebaseHelper.GetAllPersons();
        lstPersons.ItemsSource = allPersons;

        lstPersons.ScrollTo(allPersons.LastOrDefault(), ScrollToPosition.End, false);

    }

`

There is always 1 item in the database , i want to fill a Label with the name txtCheck

txtCheck.Text="{Binding Name}"

But this is only working inside the listview , and the "Label is outside the listview and then it is not working ?

Tagged:

Best Answer

  • BorisopritBorisoprit ✭✭✭
    Accepted Answer

    Found it,

    `

    public async Task GetPerson(int personId)
    {
    var allPersons = await GetAllPersons();
    await firebase
    .Child("Persons")
    .OnceAsync();
    return allPersons.Where(a => a.PersonId == personId).FirstOrDefault();
    }

    protected async override void OnAppearing()
    {
    await Task.Delay(2000);

            base.OnAppearing();
    
    
            var person = await firebaseHelper.GetPerson(Convert.ToInt32(txtId.Text));
            if (person != null)
            {
                txtId.Text = person.PersonId.ToString();
                txtCheck.Text = person.Name;
    
                 await DisplayAlert("Success", "Person Retrive Successfully", "OK");
    
            }
            else
            {
                await DisplayAlert("Success", "No Person Available", "OK");
            }
    
    
    
        }
    

    `

Answers

  • BorisopritBorisoprit Member ✭✭✭
    Accepted Answer

    Found it,

    `

    public async Task GetPerson(int personId)
    {
    var allPersons = await GetAllPersons();
    await firebase
    .Child("Persons")
    .OnceAsync();
    return allPersons.Where(a => a.PersonId == personId).FirstOrDefault();
    }

    protected async override void OnAppearing()
    {
    await Task.Delay(2000);

            base.OnAppearing();
    
    
            var person = await firebaseHelper.GetPerson(Convert.ToInt32(txtId.Text));
            if (person != null)
            {
                txtId.Text = person.PersonId.ToString();
                txtCheck.Text = person.Name;
    
                 await DisplayAlert("Success", "Person Retrive Successfully", "OK");
    
            }
            else
            {
                await DisplayAlert("Success", "No Person Available", "OK");
            }
    
    
    
        }
    

    `

Sign In or Register to comment.