logo
Tags down

shadow

Avoid recycling of the items in the Recyclerview


By : Mr. K
Date : August 01 2020, 12:00 AM
I wish this helpful for you Have you considered using ScrollView instead? You could include the different layout types you want to use inside the ScrollView, and there you would not get recycling behavior.
If that is not good enough, than I would sudgest to stick with recycler view, and not worry about views getting recycled, because it is not much of a big deal.
code :


Share : facebook icon twitter icon

How to stop RecyclerView from recycling items that are toggled visible and gone


By : TTomasS
Date : March 29 2020, 07:55 AM
will be helpful for those in need I followed Tasos suggestion and this is how it was fixed.
In BookItem I added this:
code :
private boolean descVisible = false;

public boolean isDescVisible() {
    return descVisible;
}

public void setDescVisible(boolean descVisible) {
    this.descVisible = descVisible;
}
if (bookList.isVisible()) {
            ((CardViewHolder) holder).bookDescrip.setVisibility(View.VISIBLE);
        } else {
            ((CardViewHolder) holder).bookDescrip.setVisibility(View.GONE);
        }

        ((CardViewHolder) holder).imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (bookList.isDescVisible()) {
                    ((CardViewHolder) holder).bookDescrip.setVisibility(View.GONE);
                    bookList.setDescVisible(false);

                } else {
                    ((CardViewHolder) holder).bookBody.setVisibility(View.VISIBLE);
                    bookList.setDescVisible(true);
                }
            }
        });

Drag-n-Move - How to avoid RecyclerView background fill the entire screen even there's only a few items in RecyclerView


By : Gabo124cas
Date : March 29 2020, 07:55 AM
should help you out If the RecyclerView is longer than the area allocated to it on the screen then there is no issue: Just set the background color of the RecyclerView to red. However, if the items in the RecyclerView do not fill up the space allocated to the RecyclerView in the layout then you will see the red background in the empty space. This is what you want to eliminate.
To do this, set a OnGlobalLayoutListener on the RecyclerView and check if there is excess space or not. If there is not excess space, then just set the background color to red; otherwise, create a BitmapDrawable filled with red and properly sized to provide a background to just the items on the screen and not large enough to spill into the excess area.
code :
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final RecyclerView recyclerView = new RecyclerView(container.getContext());
    recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            if (recyclerView.getChildCount() == 0) {
                return;
            }

            int lastChildBottom = recyclerView.getChildAt(recyclerView.getChildCount() - 1).getBottom();
            if (lastChildBottom >= recyclerView.getHeight()) {
                recyclerView.setBackgroundColor(Color.RED);
                return;
            }
            Bitmap bitmap = Bitmap.createBitmap(recyclerView.getWidth(), lastChildBottom, Bitmap.Config.ARGB_8888);
            bitmap.eraseColor(Color.RED);
            BitmapDrawable d = new BitmapDrawable(getResources(), bitmap);
            d.setGravity(Gravity.TOP);
            recyclerView.setBackground(d);
            recyclerView.invalidate();
        }
    });
    return recyclerView;
}
public class RecyclerViewBackground extends Drawable {
    private RecyclerView mRecyclerView;
    private Bitmap mBitmap;
    private Paint mPaint;

    RecyclerViewBackground() {
        super();
        mPaint = new Paint();
        mPaint.setColor(Color.RED);
    }

    @Override
    public void draw(Canvas canvas) {
        if (mRecyclerView.getChildCount() == 0) {
            return;
        }

        int bottom = mRecyclerView.getChildAt(mRecyclerView.getChildCount() - 1).getBottom();
        if (bottom >= mRecyclerView.getHeight()) {
            bottom = mRecyclerView.getHeight();
        }
        canvas.drawRect(0, 0, canvas.getWidth(), bottom, mPaint);
    }

    @Override
    public void setAlpha(int alpha) {
    }

    @Override
    public void setColorFilter(ColorFilter colorFilter) {
    }

    @Override
    public int getOpacity() {
        return PixelFormat.OPAQUE;
    }

    public void attachRecyclerView(RecyclerView recyclerView) {
        mRecyclerView = recyclerView;
    }
}
RecyclerViewBackground bg = new RecyclerViewBackground();
bg.attachRecyclerView(recyclerView);
recyclerView.setBackground(bg);

How to avoid double space between items when using RecyclerView with StaggeredGridLayoutManager?


By : B U
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The following code will handle StaggeredGridLayoutManager, GridLayoutManager, and LinearLayoutManager.

RecyclerView avoid to reload items?


By : MarvinAO
Date : March 29 2020, 07:55 AM
may help you . Why not have a hashmap where you store a boolean value to indicate if you have performed operation at the position?

What to use instead of RecyclerView if not recycling items


By : Jimmy
Date : March 29 2020, 07:55 AM
I wish this helpful for you You can use ListView if you don't want to recycle the list item. Here ListView
shadow
Privacy Policy - Terms - Contact Us © voile276.org