Wednesday, 29 August 2018

Highlight selected item in RecyclerView WHILE clicking

I got a RecyclerView and I worked it out how to highlight items when they get clicked and did like they tell here.

But this will highlight the item after it got clicked. I would like to have something like in a normal ListView. So the item should be highlighted while clicking. This is why I used OnTouchListener instead.

@Override
    public boolean onTouch(View v, MotionEvent event) {
        int adapterPosition = getAdapterPosition();
        if (adapterPosition == RecyclerView.NO_POSITION) return false;

        adapter.notifyItemChanged(adapter.getSelectedPos());
        adapter.setSelectedPos(adapterPosition);
        adapter.notifyItemChanged(adapter.getSelectedPos());

        if(event.getAction() == MotionEvent.ACTION_UP){
            clicks.onItemSelected(adapterPosition);
            return true;
        }

        return false;
    }

But my Problem is, that I also want to know when the user moves his finger up, so I can do what I want when it is clicked. But unfortunately this does not work. How can I achieve this?



from Highlight selected item in RecyclerView WHILE clicking

No comments:

Post a Comment