diff --git a/headerviewadapter/src/main/java/com/donkingliang/headerviewadapter/adapter/HeaderViewAdapter.java b/headerviewadapter/src/main/java/com/donkingliang/headerviewadapter/adapter/HeaderViewAdapter.java index 105d339..97b4210 100644 --- a/headerviewadapter/src/main/java/com/donkingliang/headerviewadapter/adapter/HeaderViewAdapter.java +++ b/headerviewadapter/src/main/java/com/donkingliang/headerviewadapter/adapter/HeaderViewAdapter.java @@ -63,7 +63,7 @@ public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { }; public HeaderViewAdapter(RecyclerView.Adapter adapter) { - this.mAdapter = adapter; + mAdapter = adapter; if (mAdapter != null) { //注册mAdapter的数据变化监听 mAdapter.registerAdapterDataObserver(mObserver); @@ -121,7 +121,7 @@ public int getItemViewType(int position) { } /** - * 设置被包装的adapter。 + * 设置被包装的adapter。同一个adapter对象不能设置多次。 * * @param adapter */ @@ -130,7 +130,11 @@ public void setAdapter(RecyclerView.Adapter adapter) { //被包装的adapter不能是HeaderViewAdapter。 throw new IllegalArgumentException("Cannot wrap a HeaderViewAdapter"); } - this.mAdapter = adapter; + mAdapter = adapter; + if (mAdapter != null) { + //注册mAdapter的数据变化监听 + mAdapter.registerAdapterDataObserver(mObserver); + } notifyDataSetChanged(); }