title: On swipe left, right, up, down action
body: <p>I have trouble with coding a swipe listener that would start a function. But I don't want to use fragments.</p>
  
  <p><strong>Here's the code:</strong></p>
  
  <pre><code>class Dock : AppCompatActivity(), GestureDetector.OnGestureListener
  {
      override fun onCreate(savedInstanceState: Bundle?)
      {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.dock)
          hide_bars()
      }
  
      private val swipeThreshold = 100
      private val swipeVelocityThreshold = 100
  
      override fun onFling(downEvent: MotionEvent, moveEvent: MotionEvent, velocityX: Float, velocityY: Float): Boolean
      {
          var result = false
          val diffY = moveEvent.y - downEvent.y
          val diffX = moveEvent.x - downEvent.x
          if (Math.abs(diffX) &gt; Math.abs(diffY))
          {
              // right or left swipe
              if (Math.abs(diffX) &gt; swipeThreshold &amp;&amp; Math.abs(velocityX) &gt; swipeVelocityThreshold)
              {
                  if (diffX &gt; 0)
                  {
                      swipeRight()
                  } else
                  {
                      swipeLeft()
                  }
                  result = true
              }
          } else
          {
              // up or down swipe
              if (Math.abs(diffY) &gt; swipeThreshold &amp;&amp; Math.abs(velocityY) &gt; swipeVelocityThreshold)
              {
                  if (diffY &gt; 0)
                  {
                      swipeDown()
                  } else
                  {
                      swipeUp()
                  }
                  result = true
              }
          }
          return result
      }
  
      private fun swipeUp()
      {
          Toast.makeText(this, "Swipe Top", Toast.LENGTH_LONG).show()
      }
  
      private fun swipeDown()
      {
          Toast.makeText(this, "Swipe Bottom", Toast.LENGTH_LONG).show()
      }
  
      private fun swipeLeft()
      {
          Toast.makeText(this, "Swipe Left", Toast.LENGTH_LONG).show()
      }
  
      private fun swipeRight()
      {
          Toast.makeText(this, "Swipe Right", Toast.LENGTH_LONG).show()
      }
  </code></pre>
  
  <p>I can start the app with no problem, however, when I swipe, nothing changes. No toasts, no activity started that would change the layout. That's why I'm here. Please help me.</p>
  
  <p><em>"After swipe" functions are not comprised in the code, because they are not the problem (tested) and this post couldn't be created.</em></p>