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;
}
}