Help Center

Local Navigation

Display HTML content from a resource in your application

  1. Import the required classes and interfaces.
    import net.rim.device.api.browser.field2.*;
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.container.*;
  2. Create the application framework by extending the UiApplication class. In main(), create an instance of the new class and invoke enterEventDispatcher() to enable the application to receive events. In the application constructor, invoke pushScreen() to display the custom screen for the application. The BrowserFieldDemoScreen class, described in step 3, represents the custom screen.
    public class BrowserFieldDemo extends UiApplication
    {
         public static void main(String[] args)
         {
              BrowserFieldDemo app = new BrowserFieldDemo();
              app.enterEventDispatcher();
         }
    
         public BrowserFieldDemo() 
         {
              pushScreen(new BrowserFieldDemoScreen());
         }
    }
  3. Create the custom screen by extending the MainScreen class.
    class BrowserFieldDemoScreen extends MainScreen
    {
         public BrowserFieldDemoScreen()
         {
         }
    }
  4. In the screen constructor, create an instance of the BrowserField class.
    BrowserField myBrowserField = new BrowserField();
  5. In the screen constructor, invoke add() to add the BrowserField object to the screen.
    add(myBrowserField);
  6. In the screen constructor, invoke BrowserField.requestContent() to specify the location of the resource in your application and display the HTML content.
    myBrowserField.requestContent("local:///test.html");
    Note: The BrowserField class does not access resources using a folder structure. The BrowserField class displays the first resource found that matches the specifed file name.

Code sample: Displaying HTML content from a resource in your application

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;

public class BrowserFieldDemo extends UiApplication
{
    public static void main(String[] args)
    {
        BrowserFieldDemo app = new BrowserFieldDemo();
        app.enterEventDispatcher();
    }
    public BrowserFieldDemo()
    {
        pushScreen(new BrowserFieldDemoScreen());
    }
}

class BrowserFieldDemoScreen extends MainScreen
{
    public BrowserFieldDemoScreen()
    {
        BrowserField myBrowserField = new BrowserField();
        add(myBrowserField);
        myBrowserField.requestContent("local:///test.html");
    }
}

Was this information helpful? Send us your comments.