Update activity with changes in adapter Xamarin android

0

Good morning.

I would like to know if it would be possible to update the parent activity that contains an adapter when an event occurs in it.

I explain in a little more detail: I have an activity that loads an adapter with a series of information contained in each item and a button for a change of status (for each of the items).

I would need each time the user clicks on the button to change the status of the items, it will update the parent activity.

I have attached the code of my adapter (I have omitted some parts to leave the relevant)

Thank you very much for the help.

  class adapter_listview_pedidos_asignados_int : 
    BaseAdapter<DetalleRutaAsignadaIntClass>    {

        ImageView btnEntregaRealizadaOK1;

        ImageView btnEntregaRealizadaConInci1;


        List<DetalleRutaAsignadaIntClass> items;
        Activity context;

        string _ok = "OK";

        View _view;


        public override int Count   {
            get { return items.Count; }
        }

        public override DetalleRutaAsignadaIntClass this[int position] {
            get { return items[position]; }
        }

        public adapter_listview_pedidos_asignados_int(Activity context, List<DetalleRutaAsignadaIntClass> items) : base() {
            this.context = context;
            this.items = items;
        }

        public override long GetItemId(int position)    {
            return position;
        }

        public override View GetView(int position, View convertView, ViewGroup parent)  {
            View view = null;
            DetalleRutaAsignadaIntClass item = items[position];
            if (convertView == null) {
                view = new View(context);
            }
            else {
                view = convertView;
            }

            if (view != null)       {
                view = context.LayoutInflater.Inflate(Resource.Layout.item_pedido_asign_ruta_int, null);
                _view = view;

                view.FindViewById<TextView>(Resource.Id.lblNombreLinea).Text = item.nombre_linea.ToString();
                view.FindViewById<TextView>(Resource.Id.lblDistancia).Text = item.distancia_aproximada.ToString();

                view.FindViewById<TextView>(Resource.Id.lblNombreLocalizacionOrigen).Text = item.nombre_localizacion_origen.ToString();
                view.FindViewById<TextView>(Resource.Id.lblNombreLocalizacionDestino).Text = item.nombre_localizacion_destino.ToString();


                view.FindViewById<ImageView>(Resource.Id.btnEntregaRealizadaOK1).Visibility = ViewStates.Gone;

                btnEntregaRealizadaOK1 = view.FindViewById<ImageView>(Resource.Id.btnEntregaRealizadaOK1);
                btnEntregaRealizadaOK1.Click += delegate    {
            bool res = actualiza_estado(string id_pedido, string resultado);
                //*** Aquí es donde quiero actualizar el activity padre ***//       
                };

            }
            return view;
        }

        private bool actualiza_estado(string id_pedido, string resultado) {
            bool devolver = false;

            librerias.helpers.WebService consulta = new librerias.helpers.WebService(helper.helper.url_web_service, "cambia_estado_pedido_a_finalizado_int");
            try {
                consulta.AddParameter("id_pedido", id_pedido.ToString());
                consulta.AddParameter("resultado", resultado.ToString());

                consulta.Invoke();
            }
            finally { consulta.PosInvoke(); }

            devolver = Convert.ToBoolean(consulta.ResultString);
            consulta = null;

            return devolver;
        }

    }
    
asked by raBinn 18.08.2017 в 14:08
source

2 answers

0

I just found the solution and see that I had a good time with this. Relatively simple but I leave it here for any other person: just after the call to update_I have done the following:

Intent act_actualizado= new Intent(context.Intent);
act_actualizado.SetFlags(ActivityFlags.NewTask); 
this.context.Finish(); 
Application.Context.StartActivity(act_actualizado); 

Any improvement or suggestion is, of course, appreciated.

    
answered by 29.08.2017 / 20:05
source
1

I solved it this way it works but I do not know if it's the right thing to do

ListView listaTra;
    List<mantenimientoProsesado> listaTraItems;
    bool actualizacionesBandera = false;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your application here

        SetContentView(Resource.Layout.ListaTrabajosPersonal);
        listaTra = FindViewById<ListView>(Resource.Id.ListaListaTrabajosPersonal);
        listasActualizar();
        listaTra.ItemClick += listaTra_ItemClick;
    }

    protected override void OnPostResume()
    {
        base.OnPostResume();
        if (actualizacionesBandera)
        {
            listasActualizar();
            actualizacionesBandera = false;
        }
    }

    public void listasActualizar()
    {
        listaTraItems = ;//cargas tu lista 
        listaTra.Adapter = new ListaTrabajosPersonalAdaptador(this, listaTraItems);
    }

    void listaTra_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
    {
        actualizacionesBandera = true;

        Toast.MakeText(this, listaTraItems[e.Position].ClienteAgencia, ToastLength.Short).Show();
        Intent Navegar = new Intent(this, typeof(Mantenimiento));
        StartActivity(Navegar);

    }
    
answered by 20.03.2018 в 03:52