/** * 带emptyview */ public class SmartRecyclerView extends RecyclerView { private static final String TAG = "EmptyRecyclerView"; private View emptyView; public SmartRecyclerView(Context context) { this(context, null); } public SmartRecyclerView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public SmartRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void checkIfEmpty() { if (emptyView != null && getAdapter() != null) { final boolean emptyViewVisible = getAdapter().getItemCount() == 0; emptyView.setVisibility(emptyViewVisible ? VISIBLE : GONE); setVisibility(emptyViewVisible ? GONE : VISIBLE); } } @Override public void setAdapter(Adapter adapter) { super.setAdapter(adapter); emptyView = LayoutInflater.from(getContext()) .inflate(R.layout.view_empty, null); ((ViewGroup)getParent()).addView(emptyView); emptyView.setVisibility(INVISIBLE); } }
带emptyview的reyclerview
最新推荐文章于 2018-07-30 13:24:02 发布