使用this.notifyDataSetChanged();报错时
考虑使用Handler :
//...
Handler handler=new Handler();
//线程报错
// this.notifyDataSetChanged();
handlerPostAndNotifyAdapterNotifyDataSetChanged(handler,recyclerView,this);
//...
//
/**
* 重复post message 直到recyclerView 完成显示后调用notifyDataSetChanged
* @param handler
* @param recyclerView
* @param adapter
*/
protected void handlerPostAndNotifyAdapterNotifyDataSetChanged(final Handler handler, final RecyclerView recyclerView, final RecyclerView.Adapter adapter) {
handler.post(new Runnable() {
@Override
public void run() {
if (!recyclerView.isComputingLayout()) {
adapter.notifyDataSetChanged();
} else {
handlerPostAndNotifyAdapterNotifyDataSetChanged(handler, recyclerView, adapter);
}
}
});
}