I am trying to implement a list selector for my RecyclerView grid on a touch device. My implementation works fine, but it requires a notifyItemChanged() method, which is inefficient. I have a grid with 100 elements, so if I scroll quickly (by scrolling the keyboard, therefore, onKey), the grid is distorted, as many elements are updated. Is there any way to avoid this?
activity
mRecyclerView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager(); if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case Constants.KEYCODE_UP: return moveSelection(lm, -1, true); case Constants.KEYCODE_DOWN: return moveSelection(lm, 1, true); } } return false; } }); public boolean moveSelection(RecyclerView.LayoutManager lm, int direction, boolean verticalMovement) { ...
Adapter
@Override public void onBindViewHolder(ViewHolder holder, int position) {
source share