title: Need to implement swipe left and right in webview in android
body: <p>I an developing an app which shows the contents from database into webview.</p>
  
  <p>In first screen i have index where user select an item and it opens the content in the webview. currently i have two buttons to go to next or previous item.</p>
  
  <p>Now i want to replace buttons with swipe left/right to go to next or previous item.</p>
  
  <p>Below is my code for webview </p>
  
  <pre><code>private void setupwebview(){
      final WebView wvBrowser = ( WebView ) findViewById( R.id.wvBrowser );
      wvBrowser.getSettings( ).setLoadsImagesAutomatically( true );
      wvBrowser.getSettings( ).setJavaScriptEnabled( true );
      wvBrowser.getSettings( ).setBuiltInZoomControls( true );
  
  wvBrowser.loadDataWithBaseURL( sBanner, html, this.mimeType,
              this.encoding, null );
  
      wvBrowser.setWebViewClient( new DefinitionWebViewClient( ) );
      // wvBrowser.getZoomControls( ).setVisibility( View.VISIBLE );
  
      wvBrowser.getSettings( ).setBuiltInZoomControls( true );
  
      new Handler( ).postDelayed( new Runnable( )
      {
  
          public void run( )
          {
              wvBrowser.setVisibility( View.VISIBLE );
  
              //wvBrowser.reload( );
          }
      }, 100 );
  }
  </code></pre>
  
  <p>above method i call in oncreate of the activity class.</p>
  
  <p>Customewebview ::</p>
  
  <pre><code>public class CustomWebView extends WebView{
  private GestureDetector gestureDetector;
  
  public CustomWebView(Context context) {
      super(context);
  
  }
  
  public CustomWebView(Context context, AttributeSet attrs) {
      super(context, attrs);
  }
  
  public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
  }
  
  @Override
  protected void onScrollChanged(int l, int t, int oldl, int oldt) {
      super.onScrollChanged(l, t, oldl, oldt);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
      return gestureDetector.onTouchEvent(ev) || super.onTouchEvent(ev);
  }
  
  public void setGestureDetector(GestureDetector gestureDetector) {
      this.gestureDetector = gestureDetector;
  }
  
  
  
  }
  </code></pre>
  
  <p>Gesture detector</p>
  
  <pre><code>private class CustomeGestureDetector extends SimpleOnGestureListener {      
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
          if(e1 == null || e2 == null) return false;
          if(e1.getPointerCount() &gt; 1 || e2.getPointerCount() &gt; 1) return false;
          else {
              try { // right to left swipe .. go to next page
                  if(e1.getX() - e2.getX() &gt; 100 &amp;&amp; Math.abs(velocityX) &gt; 800) {
                      Log.d( "gesture", "moving right to left" );
                      moveDown();
                      return true;
                  } //left to right swipe .. go to prev page
                  else if (e2.getX() - e1.getX() &gt; 100 &amp;&amp; Math.abs(velocityX) &gt; 800) {
                      Log.d( "gesture", "moving left to right" );
                      moveUp();
  
                      return true;
                  } 
              } catch (Exception e) { // nothing
              }
              return false;
          }
      }      
  }
  </code></pre>