I have a listView that I load from a web service. It works perfectly, now I want it to cool only every 20 seconds and for that I used the following code;
public class ListadoBC extends ActionBarActivity {
String ref = "";
String hora ="";
String op ="";
String equipo="";
int pulsado = -1;
int click = -1;
private ProgressDialog progressDialog;
ArrayList<BienCultural> listaBC = new ArrayList<BienCultural>();
ArrayList<Integer> bienes = new ArrayList<Integer>();
MyCustomAdapter dataAdapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listado_bc1);
listado();
}
public void listado()
{
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Descargando listado ...");
progressDialog.setTitle("Progreso");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCancelable(false);
ListadoAsyncTask listadoAsyncTask = new ListadoAsyncTask();
listadoAsyncTask.execute("http://swa.hol.es/conectar1.php");
}
public void actualizarDisplay()
{
progressDialog.dismiss();
dataAdapter = new MyCustomAdapter(this,R.layout.bien_cultural, listaBC);
final ListView listView = (ListView) findViewById(R.id.lista);
listView.setAdapter(dataAdapter);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
listado();
dataAdapter.notifyDataSetChanged();
handler.postDelayed(this, 20000); //now is every 2 minutes
}
}, 20000);
}
}
List saves the webService data in an ArrayList that is then passed to the adapter
It has been updated for 1 minute without problem, but suddenly it has given an error and closed the app. The logcat error is:
The content of the adapter has changed but ListView did not receive a notification Make sure the content of your adapter is not modified from a thread background, but only from the thread UI.
Any ideas?