I'm trying to create an AsyncTask
with Context
as parameter onClick
of a button
of a Alert
.
But I am getting the error:
No enclosing instance of type is accessible Alerts. Must Qualify the allocation With An enclosing instance of type Alerts (egxnew A () where x is an instance of alerts).
Alertas.java
public static void alertaHorarios(final Context context, final PerfilObj perfil) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.alerta, null);
builder.setView(v);
sonidos(context);
cargarAlerta(context,
v,
R.drawable.iconodescargar,
"Descargar datos",
"¿Desea descargar de internet los datos (horarios y tarifas) de " +
"<font color='" +
context.getResources().getColor(Modulo.cargarColorAplicacion(context, perfil.getColor())) + "'><b>" +
context.getResources().getString(R.string.app_name) + "</b></font>?",
perfil.getColor());
builder.setPositiveButton("Descargar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Modulo.reproducirSonidos(context, perfil.getSonidos(), sound, sonidoBoton);
tareaAsincronaInicio task = new tareaAsincronaInicio(context, perfil);
task.execute();
}});
builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Modulo.reproducirSonidos(context, perfil.getSonidos(), sound, sonidoBoton);
}
});
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Button b = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if(b != null) {
b.setBackgroundResource(COLOR_FONDO_BOTONES);
b.setTextSize(TAMANO_FUENTE_BOTONES);
b.setTypeface(Modulo.fontPrincipal(context));
b.setTextColor(context.getResources().getColorStateList(COLOR_FUENTE_BOTONES));
}
Button b2 = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
if(b2 != null) {
b2.setBackgroundResource(COLOR_FONDO_BOTONES);
b2.setTextSize(TAMANO_FUENTE_BOTONES);
b2.setTypeface(Modulo.fontPrincipal(context));
b2.setTextColor(context.getResources().getColorStateList(COLOR_FUENTE_BOTONES));
}
}
private class tareaAsincronaInicio extends AsyncTask<Void, Integer, Boolean> {
private Context mContext;
private PerfilObj perfilObj;
public tareaAsincronaInicio (Context context, PerfilObj perfil){
mContext = context;
perfilObj = perfil;
}
...
}