0

RT. I have a recycler view and the view holder has the item of "move imageview" , if the item's "move imageview" has the focus and you can click KeyEvent.KEYCODE_DPAD_UP or KeyEvent.KEYCODE_DPAD_DOWN to sort the item with its front or near one.I have made it for the finger to move .But for the KeyEvent the focus is not correct, i need the focus retain after the move action. Maybe i dont make myself understanded. Who can help me ? Thank you!

严彬彬
  • 1
  • 1
  • Can you explain what you mean by "the KeyEvent the focus is not correct"? or you may share some of your code. – Joshua Jul 20 '16 at 06:39
  • ok , i mean i need sort the recycle view item for listening the keyevent, for key up or key down. – 严彬彬 Jul 20 '16 at 06:43
  • @Override public void onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (mMoveItemHasFocus) { if (mCurrentMoveItemFocusPosition == 0) return; mAdapter.onItemMove(mCurrentMoveItemFocusPosition, mCurrentMoveItemFocusPosition - 1); } break; – 严彬彬 Jul 20 '16 at 06:45
  • Do you mean dragging? Anyway, you should share the code that you written. The code above is not enough. You should share all your code related to the `RecyclerView` including `Adapter`, `ViewHolder` and the layout Xmls. Also, you should edit your post and put the code there instead of posting it in the comment. – Joshua Jul 20 '16 at 06:50
  • No, not dragging. Swap two items in recycler view ,and the focus retain on the start swap item. The activity listen the KeyEvent such as KeyUp or KeyDwon. But now, the focus after swap will on the end swap item. – 严彬彬 Jul 20 '16 at 07:01
  • Ok. If your swap code works, have you try to set the focus manually? – Joshua Jul 20 '16 at 07:06
  • Yeah, the swap code is ok – 严彬彬 Jul 20 '16 at 07:09
  • mLayoutManager.getChildAt(mCurrentMoveItemFocusPosition + 1).findViewById(R.id.move).requestFocus(View.FOCUS_UP); – 严彬彬 Jul 20 '16 at 07:10
  • Sorry for Enter Key. I just dont know how to set the focus int the right way. I need the focus stay on the start swap item. – 严彬彬 Jul 20 '16 at 07:11
  • If the position is swapped, may be `mCurrentMoveItemFocusPosition` is not correct? – Joshua Jul 20 '16 at 07:12
  • But it doesn‘t make matter. – 严彬彬 Jul 20 '16 at 07:12
  • May be [this](http://stackoverflow.com/a/28838834/3673259) can help you. – Joshua Jul 20 '16 at 07:15
  • No, the variable is the start swap position. swap with mCurrentMoveItemFocusPosition + 1, or mCurrentMoveItemFocusPosition - 1 – 严彬彬 Jul 20 '16 at 07:16
  • No, it not suit for my situation. – 严彬彬 Jul 20 '16 at 07:29

0 Answers0