KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've created a small Activity which is capable of loading two different HTML strings in a webview. When I run the Activity it starts by loading the String from the page_1 variable. So far so good. The page shows as expected. I've added an onFling listener which should make the activity load the content of the page_2 variable. The problem is that even though the onFling is called and the loadUrl is called the webview isn't updated? My activity looks like this: import android.app.Activity; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.webkit.WebView; public class Test extends Activity { private GestureDetector mGestureDetector; private WebView mWebView; private int mPageIndex; private static final String page_1 = "<html><body>Hello page 1</body></html>"; private static final String page_2 = "<html><body>Hello page 2</body></html>"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); mWebView = (WebView) findViewById(R.id.webview); mWebView.loadData(page_1, "text/html", "utf-8"); setupGestureDetection(); mPageIndex = 0; } private void setupGestureDetection() { mGestureDetector = new GestureDetector(new MyGestureDetector()); mWebView.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return mGestureDetector.onTouchEvent(event); } }); } class MyGestureDetector extends GestureDetector.SimpleOnGestureListener { private static final int SWIPE_DISTANCE_THRESHOLD = 120; private static final int SWIPE_VELOCITY_THRESHOLD = 200; private boolean isHorizontalSwipe(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (Math.abs(velocityX) > SWIP
Tags (comma-separated)
Save Edits
Cancel