Good afternoon
I have an AlertDialog in the Multichoice actionbar, which I fill from a webservices.
I need that when the user selects one or x options and clicks on ok, those options are saved in the Sharepreferences of the system, so when the dialog is generated again, I save the selected options.
I leave you a code where I create my Alertdialog
@Override
protected void onPostExecute(ArrayList arrayList){
super.onPostExecute(arrayList);
final String[] zona = new String[ZonaArrayList.size()];
// zona = ZonaArrayList.toArray(zona);
for(int i=0; i<ZonaArrayList.size(); i++){
//Obtiene el campo Descripción y lo agrega al array de strings "zona".
zona[i] = ZonaArrayList.get(i).getDescripcion();
// zona[i] = ZonaArrayList.get(i).getClave();
//
}
AlertDialog.Builder dialog=new AlertDialog.Builder(Clientes.this);
dialog.setTitle("Selecciona la(s) Zonas a Visitar");
final boolean[] selZona={false,false,false};
dialog.setMultiChoiceItems(zona,selZona,new DialogInterface.OnMultiChoiceClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
if(arg2) {
Toast.makeText(getApplicationContext(), "Zona Seleccionada " + zona[arg1],Toast.LENGTH_SHORT).show();
}
}
});
dialog.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//Mandar a llamar metodo Clientes con el filtro
SharedPreferences settings = getSharedPreferences("ONC_Settings", 0);
AsynClien task = new AsynClien(settings.getString("ONControlWSURL", "").toString());
//Call execute
task.execute();
}
});
dialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alertDialog=dialog.create();
alertDialog.show();
}
}