Disable click on RecyclerView inside a SwipeRefreshLayout

风流意气都作罢 提交于 2019-11-27 21:37:36

Use logic we had with ListAdapter. This will disable adapter items, instead their parent.

public interface RecyclerViewItemEnabler{
  public boolean isAllItemsEnabled();
  public boolean getItemEnabled(int position);
}

And implementation should look like this:

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements RecyclerViewItemEnabler{

    @Override
    public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
        super.onViewAttachedToWindow(holder);
        holder.itemView.setEnabled(isAllItemsEnabled());
        //or do this in onBindViewHolder()
    }
    @Override
    public boolean isAllItemsEnabled(){ return mAllEnabled; }

    @Override
    public boolean getItemEnabled(int position){
       return true;
    }
    public void setAllItemsEnabled(boolean enable){
      mAllEnabled = enable;
      notifyItemRangeChanged(0, getItemCount());
    }

}

Usage: mRecylerAdapter.setAllItemsEnabled(!mSwipeRefreshLayout.isRefreshing());

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!