Android 执行异步操作时,RecyclerView不显示数据
在notifyChanges()中,如果没有任何异步操作,my recyclerview将显示数据。但是当我执行异步操作时,RecyclerView是空的。原因可能是什么?提前谢谢Android 执行异步操作时,RecyclerView不显示数据,android,android-recyclerview,android-asynctask,google-cloud-firestore,android-livedata,Android,Android Recyclerview,Android Asynctask,Google Cloud Firestore,Android Livedata,在notifyChanges()中,如果没有任何异步操作,my recyclerview将显示数据。但是当我执行异步操作时,RecyclerView是空的。原因可能是什么?提前谢谢 profileList = changes; 不要从主线程以外的任何其他线程调用notifyDataSetChanged()。只需从doInBackground()中删除对invalidate()的调用,并将其添加到onPostExecute() 当对ArrayList进行迭代时,不应修改它。不要在ArrayLis
profileList = changes;
不要从主线程以外的任何其他线程调用
notifyDataSetChanged()
。只需从doInBackground()
中删除对invalidate()
的调用,并将其添加到onPostExecute()
当对ArrayList进行迭代时,不应修改它。不要在ArrayList上使用remove()
方法,而要在迭代器上使用remove()
方法
@Override
protected void onPostExecute(Void aVoid) {
Log.w("PROCESS EXECUTED", String.valueOf(profileList.size()));
invalidate();
}
不要从主线程以外的任何其他线程调用
notifyDataSetChanged()
。只需从doInBackground()
中删除对invalidate()
的调用,并将其添加到onPostExecute()
当对ArrayList进行迭代时,不应修改它。不要在ArrayList上使用remove()
方法,而要在迭代器上使用remove()
方法
@Override
protected void onPostExecute(Void aVoid) {
Log.w("PROCESS EXECUTED", String.valueOf(profileList.size()));
invalidate();
}
我相信
ConcurrentModificationException
的问题就在这里
@Override
protected Void doInBackground(List<ProfileSearchResult>... lists) {
synchronized (profileList) {
Iterator<ProfileSearchResult> iter = profileList.iterator();
while (iter.hasNext()) {
ProfileSearchResult result = iter.next();
if(false == profileListNew.contains(result)){
iter.remove();
}
}
iter = profileListNew.iterator();
while (iter.hasNext()) {
ProfileSearchResult result = iter.next();
if(false == profileList.contains(result)){
profileList.add(result);
}
}
return null;
}
}
Iterator iter=profileList.Iterator();
while(iter.hasNext()){
ProfileSearchResult=iter.next();
if(false==profileListNew.contains(结果)){
profileList.remove(result);//我相信ConcurrentModificationException
的问题就在这里
@Override
protected Void doInBackground(List<ProfileSearchResult>... lists) {
synchronized (profileList) {
Iterator<ProfileSearchResult> iter = profileList.iterator();
while (iter.hasNext()) {
ProfileSearchResult result = iter.next();
if(false == profileListNew.contains(result)){
iter.remove();
}
}
iter = profileListNew.iterator();
while (iter.hasNext()) {
ProfileSearchResult result = iter.next();
if(false == profileList.contains(result)){
profileList.add(result);
}
}
return null;
}
}
Iterator iter=profileList.Iterator();
while(iter.hasNext()){
ProfileSearchResult=iter.next();
if(false==profileListNew.contains(结果)){
profileList.remove(结果);//原因:java.util.ConcurrentModificationException我也收到了这个错误!谢谢你的帮助!@SachinTitus你能发布完整的堆栈跟踪吗?当然……一秒钟原因:java.util.ConcurrentModificationException我也收到了这个错误!谢谢你的帮助!@SachinTitus你能发布完整的堆栈跟踪吗?当然……一秒钟
@Override
protected Void doInBackground(List<ProfileSearchResult>... lists) {
synchronized (profileList) {
Iterator<ProfileSearchResult> iter = profileList.iterator();
while (iter.hasNext()) {
ProfileSearchResult result = iter.next();
if(false == profileListNew.contains(result)){
iter.remove();
}
}
iter = profileListNew.iterator();
while (iter.hasNext()) {
ProfileSearchResult result = iter.next();
if(false == profileList.contains(result)){
profileList.add(result);
}
}
return null;
}
}
Iterator<ProfileSearchResult> iter = profileList.iterator();
while (iter.hasNext()) {
ProfileSearchResult result = iter.next();
if(false == profileListNew.contains(result)){
profileList.remove(result); // <------- here <-------
}
}