Wait with Alertdialog()

Asked

Viewed 218 times

0

good! My problem is with the AlertDialog asynchronous of Xamarin.Android. I have a class with a method that assembles an alert with some fields... With the data of these fields, I assemble an object to make mine CRUD. The problem is time to call the AlertDialog, when I call, it is mounted and then instantiates my object with the empty values of the AlertDialog, for it is asynchronous.

llCompraAtiva.Click += delegate
{
    this.RunOnUiThread(() => dadosCompra = Util.modalPagamento(this));
    string teste = dadosCompra.NumCartao;
};

I thought I’d put something together Thread, but I didn’t do well...

Summarizing: I need to enter the data in the inputs, then instantiate the object with the values of these inputs.

Can someone help me? Tks

  • What is the return of: Util.modalPagamento(this) ? It is a Task> ?

  • Forget it, I mistook it for Xamarin.Forms =D

  • Hahaha, no problem, helped me alot! D

1 answer

1


Blocking the Main Thread is not recommended to wait for the Dialog, so you need to provide Handler for the Dialog itself to handle, so when the user confirms the action in the Dialog, this, will trigger the Handler to fill the object.

I wrote an example, but I didn’t have time to test it, I think it’ll give you an idea

using (var builder = new AlertDialog.Builder(this))
{
    var title = "Edite seus detalhes: ";
    builder.SetTitle(title);
    builder.SetPositiveButton("OK", OkAction);                
    var customDialog = builder.Create();
    customDialog.Show();
}

And the button Handler:

private void OkAction(object sender, DialogClickEventArgs e)
{
    var botao = sender as Button; 
    if (botao != null)
    {
        var resultado = BuscaResultado();
        _dadosCompra.NumeroCartao = resultado;
    }
}
  • Got it here, helped me a lot! Thanks @Fbatista

Browser other questions tagged

You are not signed in. Login or sign up in order to post.