Question: I'm using a different `Thread` to clear the Adapter's `List` and sometimes I get an `IndexOutOfBoundsException`. 

I suppose that the problem is that somewhere in the middle of the process of the Custom Adapter filling the `ListView`, the second Thread calls `list.clear()` causing the `list.size()` to return 0, causing an out of bounds somewhere.

How do I make this thread safety with synchronized (in the case this would solve it)?

```
//onCreate
fillList(list);  // fills the list
new AsyncTaskSubclass().execute(); // clear the list on a different Thread

```

**Edit:** I think the problem comes on the fact that the `AsyncTask` is clearing the list that the `ArrayAdapter` subclass uses, is there any way to change the `List` that the adapter uses?

Answer: 
You could use a synchronized list:

```
List<Item> list = Collections.synchronizedList(new ArrayList<Item>());

```
It would be good to have some more code.

If using an `AsyncTask` you should call `publishProgress()` in your `doInBackground()` method when you want to clear the lost, and then do this clear in `onProgressUpdate()` (`add()` or `remove()`). You should avoid manipulating UI elements from outside the UI Thread.

And why not setting a new Adapter with the new List? So you cook your list asynchronously and then call `ListView.setAdapter()` in the UI Thread (e.g. in `onProgressUpdate()` or `onPostExecute()`).