title: Android: RecyclerView item with LongClickListener and and drag and drop
body: <p>So, I'm trying to figure this out. I see many posts online about having RecyclerView items with both swipe and drag-- I've got that down. But what I can't get to work is both drag and long press actions.</p>
  <p>I've got working code for both drag and longclick, the problem is, when I long click a recycler item, it's a toss up whether it will run the longclick function or the drag function.</p>
  <p>Here is the code for the long click listener:</p>
  <pre><code>        holder.itemView.setOnLongClickListener {
               currentNote.toggleSelection(it)
               // change the MainActivity menu to the selection menu
               MainActivity.currentMenu = R.menu.menu_select
               (it.context as Activity).invalidateOptionsMenu()
  
               // set a flag to change the onClickListener to select notes rather than edit/view
               SELECTING = true
               notifyDataSetChanged()
  
               true  
  </code></pre>
  <p>Simple enough.
  And here is how I implemented the drag action:</p>
  <pre><code>        val itemTouchHelper = ItemTouchHelper(object : ItemTouchHelper.Callback() {
          override fun isLongPressDragEnabled() = true
          override fun isItemViewSwipeEnabled() = true
  
          override fun getMovementFlags(
              recyclerView: RecyclerView,
              viewHolder: RecyclerView.ViewHolder
          ): Int {
              val dragFlags = UP or DOWN or START or END
              val swipeFlags = LEFT or RIGHT
              return makeMovementFlags(dragFlags, swipeFlags)
          }
  
          override fun onMove(
              recyclerView: RecyclerView,
              viewHolder: RecyclerView.ViewHolder,
              target: RecyclerView.ViewHolder
          ): Boolean {
              val fromPosition = viewHolder.adapterPosition
              val toPosition = target.adapterPosition
              val item = NOTES_ARRAY.removeAt(fromPosition)
              NOTES_ARRAY.add(toPosition, item)
              recyclerView.adapter!!.notifyItemMoved(fromPosition, toPosition)
              return true
          }
      })
  </code></pre>
  <p>This is a note taking app, so I use the long press action for doing multi select. So the question is, how can I differentiate between a long press action and a drag action, as they are both bound the the &quot;long press.&quot;</p>
  <p>I know that this is the problem, because if I comment out the onLongClickListener, I can easily drag and drop without issue.</p>