Switch pages/classes in BlackBerry
I am currently developing a blackberry app. the scenario is when a user clicks on a menu item, it will go to another page. Currently there are 3 classes, MyApp, SecondPage and MyScreen. the codes below belongs to SecondPage.
From MyApp, I am trying to pushScreen to SecondPage after the user clicks on a MenuItem but I'm unable to do so because it(SecondPage) is extending UiApplication am I right? but if I change it to extend MainScreen, it cant pushScreen(_screen). any suggestions please?
Thanks, Hend
class MyApp extends UiApplication{
//creating a member variable for the MainScreen
MainScreen _screen= new MainScreen();
//string variables to store the values of the XML document
String _node,_element;
Connection _connectionthread;
public static void main(String arg[]){
MyApp application = new MyApp();
//create a new instance of the application
//and start th开发者_JS百科e application on the event thread
application.enterEventDispatcher();
}
public MyApp() {
_screen.setTitle("Agenda");//setting title
//_screen.add(new RichTextField("Requesting....."));
_screen.add(new SeparatorField());
pushScreen(_screen); // creating a screen
//creating a connection thread to run in the background
_connectionthread = new Connection();
_connectionthread.start();//starting the thread operation
}
public void updateField(String node, String element)
{
synchronized (UiApplication.getEventLock())
{
String title = "My App";
_screen.add(new RichTextField(/*node + " : " +*/ element + "\n" ));
if (node.equals(title))
{
_screen.add(new SeparatorField());
}
}
}
Your screens need to inherit from Screen, not from UiApplication. If you look at the docs for UiApplication, you see there is a static method getUiApplication()
that will return you a reference to the UiApplication for purposes of pushing screens (among other useful tasks).
So, instead of just pushScreen(_screen)
your code would be UiApplication.getUiApplication().pushScreen(_screen)
.
精彩评论