This is my code:
public class ListasCompra extends ListActivity {
private ArrayList<Lista> listaCompras = null;
private ListaAdapter adaptador = null;
private static ListasCompra instancia = null;
private static Context context = null;
private Button aceptar = null;
private Button nueva = null;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.lista_de_listas);
listaCompras = LocalService.getDbListas().getListas();
aceptar = (Button)findViewById(R.id.aceptarlistas);
aceptar.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
finish();
}
});
nueva = (Button)findViewById(R.id.nuevalistas);
nueva.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(context, NuevaLista.class));
//finish();
}
});
if(listaCompras!=null){
adaptador = new ListaAdapter(this, listaCompras);
setListAdapter(adaptador);
}else{
listaCompras = new ArrayList<Lista>();
adaptador = new ListaAdapter(this, listaCompras);
setListAdapter(adaptador);
}
context = this;
instancia = this;
}
/**
* Ciclo Vida de Actividad
*/
@Override
public void onDestroy(){
super.onDestroy();
}
@Override
public void onResume(){
super.onResume();
listaCompras = LocalService.getDbListas().getListas();
adaptador = new ListaAdapter(context, listaCompras);
adaptador.notifyDataSetChanged();
}
What I want, is the adapter to update everytime it gets on the method “onResume”, which is everytime the Activity re-appears for the user……
My problem is that it is NOT updating using this method, anybody knows why??
Thanks!
Dont create your adapter every time you resume your activity. Create it once in
onCreate()and then callnotifyDataSetChanged()inonResume().BUT, your biggest issue, is that you are creating a new Adapter in onResume() and never attaching it to the ListView! If you must keep your code as is, then add
setListAdapter(adaptador)after you create your new adapter inonResume()