Search code examples
androidandroid-webviewswipegesture

Load next url when swipe in android


I'm coding an android application. I have an array containing many url. I have loaded the first url on webview in mainactivity, and i want to load next url when i swipe. I'm using webview to load the url. So now I have to do as to how to load the next url by swipe


Solution

  • 1- Use this library and follow this wiki for easy gesture detect.

    2- Get next item of array and load it to WebView.

    Example code:

    myView.setOnTouchListener(new OnSwipeTouchListener(this) {
      @Override
      public void onSwipeDown() {
        Toast.makeText(MainActivity.this, "Down", Toast.LENGTH_SHORT).show();
      }
    
      @Override
      public void onSwipeLeft() {
        Toast.makeText(MainActivity.this, "Left", Toast.LENGTH_SHORT).show();
      }
    
      @Override
      public void onSwipeUp() {
        Toast.makeText(MainActivity.this, "Up", Toast.LENGTH_SHORT).show();
      }
    
      @Override
      public void onSwipeRight() {
    
        Iterator<String> it = al.iterator();
        while (it.hasNext()) {
            yourWebView.loadUrl(it.next());
        }
    
      }
    });
    

    I don't have eclipse but it must be something like that.