Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000
Accepted Solution

how to make a different screen the main one?

hi, i've got an UiApplication in which i need to implement few MainScreens. actually there is one MainScreen (the one which is at the beginning pushScreen()) and few Managers which will behaves as the MainScreen. i overwrote onMenu method and add few items. how can i do, that when i click on the proper item Manager1 is set to be the main and visible screen?

 

kind regards

 

 

Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: how to make a different screen the main one?

If you are asking how to switch you managers to be visible, you can use the replace(Field,Field) method of the Screen/Manager class. You will need to keep track of which manager is visible to switch out the correct ones or you will get an exception.
Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to make a different screen the main one?

but this replaces fields.. in my case the situation is like that:

 

class A extends MainScreen{}

 

class B extends MainScreen{}

 

class C extends MainScreen{}

 

the one, which is pushScreen() at the beginning is A class. then i overwrote a onMenu method and added items:

 

switchA

switchB

switchC

 

and ok, at the beginning i'm in A-screen. when i click on menu and chose 'switchB' i want B screen to be active. when i click on 'switchC' i want C to be active..

 

how can i do that?

Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: how to make a different screen the main one?

For that you would just push and pop screens as normal, though you can only have one instance of a screen on the display stack at a time.
Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to make a different screen the main one?

i know that i can only have one screen active at a time. but there must be a possibility to switch between them somehow.. there are houndrets of applications doing that..
Please use plain text.
Developer
Developer
CMY
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: how to make a different screen the main one?

In my experience, you can push/pop screens and save the data that you need to pass back and forth with callback mehods, or you can create multiple managers in a single screen class and switch them in and out with the replace method. Those are the two ways that I use.
Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to make a different screen the main one?

ok, so how can i switch screens (as i asked before) ?
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to make a different screen the main one?

[ Edited ]

1. You can only use one Screen and three different manger and switch between the managers depending on your menu.

 

2. Or you can use three different screen. In that case all three screen need the similar type of menu. Then pop and push screens from that 

    menus. Something like this:

public class MainApplication extends UiApplication
{
public MainApplication()
{
super();
pushScreen(new A());
}
public static void main(String[] args)
{
MainApplication main = new MainApplication();
main.enterEventDispatcher();
}

 

public class A extends MainScreen
{
public A()
{
this.add(new LabelField("A"));
}

private MenuItem menuA = new MenuItem("switchA",100,10)
{
public void run()
{
//do nothing
//you are already in screen A
}
};

private MenuItem menuB = new MenuItem("switchB",150,10)
{
public void run()
{
popScreen();
UiApplication.getUiApplication().pushScreen(new B());
}
};

private MenuItem menuC = new MenuItem("switchC",200,10)
{
public void run()
{
popScreen();
UiApplication.getUiApplication().pushScreen(new C());
}
};

protected void makeMenu(Menu menu, int instance)
{
menu.add(menuA);
menu.add(menuB);
menu.add(menuC);
// default menu
//super.makeMenu(menu, instance);
}
}

public class B extends MainScreen
{
public B()
{
this.add(new LabelField("B"));
}
//add menu like A
}

public class C extends MainScreen
{
public C()
{
this.add(new LabelField("C"));
}
//add menu like A
}
}

 

Regards

Bikas

 

Message Edited by bikas on 07-05-2009 09:34 PM
Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to make a different screen the main one?

great! thx :smileyhappy:)

 

 

 kind regards

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to make a different screen the main one?

You are welcome. :smileyhappy:

 

Please use plain text.