【发布时间】:2013-07-22 20:24:37
【问题描述】:
我正在使用不同的Thread 来清除适配器的List,有时我会得到IndexOutOfBoundsException。
我想问题是在自定义适配器填充ListView 的过程中的某个地方,第二个线程调用list.clear() 导致list.size() 返回0,导致某处越界。
如何使用同步使这个线程安全(如果这会解决它)?
//onCreate
fillList(list); // fills the list
new AsyncTaskSubclass().execute(); // clear the list on a different Thread
编辑:我认为问题在于AsyncTask 正在清除ArrayAdapter 子类使用的列表,有没有办法改变适配器的List用途?
【问题讨论】:
标签: java android android-asynctask thread-safety synchronized