可能出現(xiàn)的原因
1.在子線程中調(diào)用了notifyDataSetChanged;
2.適配器中數(shù)據(jù)源為空。
踩坑記(適配器中數(shù)據(jù)為空)
初始化代碼沒有問題
mTypeConditionData = new ArrayList<>();
mTypeAreaConditionAdapter = new TypeAndAreaAdapter(getActivity(), mTypeConditionData);
mTypeAreaRecycler.setAdapter(mTypeAreaConditionAdapter);
在請求到數(shù)據(jù)后,對數(shù)據(jù)源進行如下操作。
private ArrayList<ChooseDateBean> getCategoryData(FilterItemInfoBean[] data) {
if (data == null || data.length <= 0) {
return null;
}
ArrayList<ChooseDateBean> beans = new ArrayList<>();
for (FilterItemInfoBean aData : data) {
if ("category_id".equals(aData.getName()) || "meetingroom_space".equals(aData.getName())) {
FilterItemOptionInfoBean[] optionInfoBean = aData.getOptions();
if (optionInfoBean == null) {
continue;
}
beans.add(new ChooseDateBean(TypeAndAreaAdapter.TYPE_TITLE, aData.getLabel()));
for (FilterItemOptionInfoBean anOptionInfoBean : optionInfoBean) {
ItemContentBean bean = new ItemContentBean();
bean.setText(anOptionInfoBean.getLabel());
bean.setSelected(false);
beans.add(new ChooseDateBean(TypeAndAreaAdapter.TYPE_ITEM, bean));
}
}
}
return beans;
}
更新適配器
mTypeConditionData = getCategoryData(data);
mTypeAreaConditionAdapter.notifyDataSetChanged();
看一張圖來解釋一下為什么這樣做會有問題

解釋
所以此時更新適配器時,適配器中的數(shù)據(jù)A對象size還是為0,recyclerview看起來沒有任何的變化。
(綁定的綁寫錯了,大家當作沒看到喔??)