这是我每次强制 webview 更新的方法,请参见代码:// WEBVIEW
package com.example.scroll;
// philip r brenan at gmail.com, www.appaapps.com
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
public class MainActivity extends Activity
{protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(new MyWebView(this));
}
class MyWebView extends WebView
{MyWebView(Context Context)
{super(Context);
getSettings().setJavaScriptEnabled(true);
addJavascriptInterface(this, "Android");
new Thread()
{public void run()
{for(int j = 0; j < 100; ++j)
{post(new Runnable()
{public void run()
{loadData(content(), "text/html", "utf-8"); // Display in browser
}
});
try {Thread.sleep(5000);} catch(Exception e) {}
}
}
}.start();
}
int c = 0, C = 1;
String content()
{final StringBuilder s = new StringBuilder();
//s.append("<html id="+(C++)+"><body>"); // WEBVIEW REFRESHES CORRECTLY ***************
s.append("<html><body>"); // WEBVIEW DOES NOT REFRESH ******************
s.append("<h1 id=11>1111</h1>");
s.append("<script>location.href = '#22';</script>");
for(int i = 0; i < 10; ++i) s.append("<p>"+c+c+c); ++c;
s.append("<h1 id=22>2222</h1>");
for(int i = 0; i < 10; ++i) s.append("<p>"+c+c+c); ++c;
Log.e("AAAAAA", "content="+s.toString());
s.append("</body></html>");
return s.toString();
}
}
}