Problem with loading data from local bd to two pickers

Asked

Viewed 79 times

1

Hello. I have two pickers that load data from an api. A Picker brings data from categories and the other subcategory. When selecting a category the Picker subcategory is loaded with data from the corresponding subcategory. Save this selected data in a local comic. So far so good.

The problem occurs when I upload the data from the local comic to the pickers to make the registration edit. The category Picker brings the data without problem, but the category Picker sometimes brings the data and sometimes not.

private async void VerificaClassificadoBaseLocal()
    {
        if (DataBase.GetClassificado() != null)
        {
            ActIndicator.IsVisible = true;
            ActIndicator.IsRunning = true;

            try
            {
                var dadosSituacao = await SituacaoClassificadoService.VerificaSituacaoClassificado(DataBase.GetAppKey());

                LblSituacao.Text = dadosSituacao.situacao;
                LblObservacao.Text = dadosSituacao.obs;

                var dadosClassificadoLocal = DataBase.GetClassificado();

                List<Categoria> ListaCategorias = await CategoriaService.GetCategoria(DataBase.GetAppKey());
                var _categoria = ListaCategorias.FindIndex(c => c.categoria == dadosClassificadoLocal.categ);
                PckCategoria.SelectedIndex = _categoria;

                var objCategoria = (Categoria)PckCategoria.SelectedItem;
                List<SubCategoria> ListaSubCategorias = await SubCategoriaService.GetSubCategoria(DataBase.GetAppKey(), objCategoria.idcategoria);
                var _subCategoria = ListaSubCategorias.FindIndex(s => s.subcategoria == dadosClassificadoLocal.subcateg);
                PckSubCategoria.SelectedIndex = _subCategoria;

                List<Hora> ListaHoras = Horarios.GetHoras();
                var Hora1Inicial = ListaHoras.FindIndex(h => h.Horas == dadosClassificadoLocal.contato_h1.Substring(0, 5));
                PckHora1Inicial.SelectedIndex = Hora1Inicial;

                var Hora1Final = ListaHoras.FindIndex(h => h.Horas == dadosClassificadoLocal.contato_h1.Substring(5, 5));
                PckHora1Final.SelectedIndex = Hora1Final;

                var Hora2Inicial = ListaHoras.FindIndex(h => h.Horas == dadosClassificadoLocal.contato_h2.Substring(0, 5));
                PckHora2Inicial.SelectedIndex = Hora2Inicial;

                var Hora2Final = ListaHoras.FindIndex(h => h.Horas == dadosClassificadoLocal.contato_h2.Substring(5, 5));
                PckHora2Final.SelectedIndex = Hora2Final;

                TxtTitulo.Text = dadosClassificadoLocal.titulo;
                TxtTexto.Text = dadosClassificadoLocal.texto;
                TxtTelefone.Text = dadosClassificadoLocal.contato_tel;
                TxtEmail.Text = dadosClassificadoLocal.contato_email;

            }
            catch (Exception erro)
            {
                await DisplayAlert("Erro", "Erro => " + erro, "Ok");
            }

            ActIndicator.IsVisible = false;
            ActIndicator.IsRunning = false;
        }
    }
  • Do other pickers after the subcategory always load the selected data? Yes. Is this "sometimes the data and sometimes not" random? Yes, if I try 5 times he charge 5 times and may not charge 5.

  • Ok. Are bindings involved in this whole story? Tried to replace the use of objCategoria for ListaCategorias[_categoria]?

  • I’m thinking there must be some out-of-sync operation between the time you arrow the SelectedIndex and the component (category Picker) provides SelectedItem, and sometimes this objCategoria which you try to catch to figure out the subcategory may be coming null. Try to give an Alert when it returns null or when _subCategoria return an invalid index...

  • I expressed myself badly above. The Picker subcategory when I load the data from the local bd it loads the subcategories, but what happens is that it does not show ("not from the display") in the Picker of the subcategory it saves in the bd. For example: The category Picker loads the categories of the api and shows on the screen the category saved in bd,ex. Animals; The Picker subcategory loads the subcategories of the api and has to show the saved subcategory in the local comic, in which case it would have to show Dogs. Only this sometimes does not occur. I have checked before and the data is brought from the api, but I will try what you said.

No answers

Browser other questions tagged

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