簡體   English   中英

刪除項目,並且不要在GridLayoutManager Recyclerview中留出空間

[英]Remove item and don't leave space in GridLayoutManager Recyclerview

我在我的recyclerview中使用的跨度為2的GridLayoutManager。 我嘗試使用。

itemView.setVisibility(View.GONE);
itemView.setLayoutParams(new RecyclerView.LayoutParams(0, 0)); 

但它在recyclerview內留有空間。 那么有沒有辦法隱藏和刪除recyclerview內部的空間?

編輯 (其他代碼)我正在使用FirebaseRecyclerAdapter來顯示所有數據。

private ArrayList<String> mWorldGroupKeys;

@Override
protected void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull Groups model) {
    String groupKeys = getRef(position).getKey();

    if (!mWorldGroupKeys.contains(groupKeys)) {
        holder.layoutHide(position);
        return;
    }

    holder.bind(model);
}

class ViewHolder extends RecyclerView.ViewHolder {

      void layoutHide(int pos) {

          notifyItemRemoved(pos);
          //Gave me an error of:
          //IllegalStateException: Cannot call this method while 
          //RecyclerView is computing a layout or scrolling
          //android.support.v7.widget.RecyclerView
       }
}

您可以使用notifyItemRemoved(); notifyDataSetChanged(); 從適配器列表中刪除該項目后。 這兩個功能將刷新列表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM