0
我想顯示加載網頁的進度。我使用BrowserFieldListener來計算網頁的進度。但屏幕上沒有顯示。我如何計算這一進展的百分比?計算加載黑莓網頁的進度
類BrowserFieldDemoScreen擴展MainScreen {
public BrowserFieldDemoScreen()
{
BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
myBrowserFieldConfig.setProperty(BrowserFieldConfig
.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
BrowserField browserField = new BrowserField();
browserField.requestContent("http://www.blackberry.com");
browserField.addListener(new BrowserFieldListener() {
public void documentAborted(BrowserField browserField, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
String url = document.getBaseURI();
browserField.getErrorHandler().displayContentError(url, "Aborted loading document '" + title + "'");
}
super.documentAborted(browserField, document);
}
public void documentCreated(BrowserField browserField, ScriptEngine scriptEngine, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
String url = document.getBaseURI();
System.out.println("[" + this.getClass().getName() + "] Document '" + title + "' created for URL " + url);
}
super.documentCreated(browserField, scriptEngine, document);
}
/**
*
* @param browserField - The BrowserField to which the document belongs
* @param document - The document for which this event belongs.
*/
public void documentError(BrowserField browserField, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
String url = document.getBaseURI();
browserField.getErrorHandler().displayContentError(url, "Error loading document '" + title + "'");
}
super.documentError(browserField, document);
}
public void documentLoaded(BrowserField browserField, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
System.out.println("[" + this.getClass().getName() + "] Document '" + title + "' loaded");
}
super.documentLoaded(browserField, document);
}
public void documentUnloading(BrowserField browserField, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
System.out.println("[" + this.getClass().getName() + "] Document '" + title + "' unloading");
}
super.documentUnloading(browserField, document);
}
public void downloadProgress(BrowserField browserField, ContentReadEvent event) throws Exception
{
if ((browserField != null) && (event != null))
{
String title = browserField.getDocumentTitle();
double amtComplete = event.getItemsRead()/event.getItemsToRead();
System.out.println("[" + this.getClass().getName() + "] Document '" + title + "' loading " + String.valueOf(amtComplete) + "% complete");
}
super.downloadProgress(browserField, event);
}});
}
}
看我的編輯你能告訴我什麼問題 – mobileDeveloper
示例代碼只打印控制檯的當前進度。您需要重寫'downloadProgress'方法來更新進度條。 我在黑莓支持論壇上發現了一個例子[here](http://supportforums.blackberry.com/t5/Java-Development/How-to-track-progress-of-page-loads-in-您-BrowserField2/TA-p/617436)。 –
我看到這個鏈接時,我嘗試它的網頁沒有顯示,進度是0,當我點擊輸入時, – mobileDeveloper