我创建了一个小的Activity,它能够在webview中加载两个不同的HTML字符串.当我运行Activity时,它通过从page_1变量加载String来开始.到现在为止还挺好.该页面按预期显示.我添加了一个onFling监听器,它应该使活动加载page_2变量的内容.问题是,即使调用onFling并调用loadUrl,webview也不会更新?
我的活动如下:
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 …Run Code Online (Sandbox Code Playgroud)