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
Contributor
Napolean
Posts: 11
Registered: ‎11-28-2012
My Device: Curve 9320
My Carrier: Vodafone

Adding a new mainscreen object as a child of the delegateManager of another MainScreen gives exception.

 

Hi

 

When I am adding a new mainscreen object as a child of the delegateManager of another MainScreen  it gives exception.
    
    Since we know that :
    Any object of type Field can be added to a manager, including other managers and screens.If a manager or a screen is added to the current manager of a screen, they become child objects and behave as any other field.
    
    So when I tried to add a new MainScreen() object as a child of the current MainScreen, it gives exception.
    Yes I can do pushScreen() but that will be like replacement of current Screen. Actually I need to add new MainScreen object with in the current MainScreen.

 

MyMainScreen :

public class MyMainScreen extends MainScreen implements FieldChangeListener
{
	private ButtonField btnField = null;
	private NewChildScreen testScreen = null;

	public MyMainScreen()
	{
		btnField = new ButtonField("Hello", ButtonField.CONSUME_CLICK | ButtonField.USE_ALL_WIDTH
				| ButtonField.FIELD_HCENTER);
		btnField.setMargin(10, 0, 10, 10);
		testScreen = new NewChildScreen();
		add(btnField);
		btnField.setChangeListener(this);
	}

	protected boolean onSavePrompt()
	{
		return true;
	}

	protected boolean navigationClick(int status, int time)
	{
		fieldChangeNotify(11);
		return true;
	}

	public void fieldChanged(Field field, int context)
	{
		if (field == btnField)
		{
			try
			{				
				add(testScreen);
			}
			catch (Exception e)
			{
				Dialog.alert("Exception : "+e.getMessage());
			}
		}
	}

}

 

 NewChildScreen:

public class NewChildScreen extends MainScreen
{	 
	private ButtonField button = null;
	
	public NewChildScreen()
	{
		super(USE_ALL_HEIGHT | USE_ALL_WIDTH);
		setTitle("New Screen");	
		getMainManager().setBackground(BackgroundFactory.createSolidBackground(Color.BLUEVIOLET));
		button =new ButtonField("New Button", ButtonField.FIELD_HCENTER); 
		add(button);
		
	}
}

 

Is there any mistake I am committing while implementation.

 

I have been trying to implement this but not succeeded yet. I also searched forum but didn't got much help about my problem.

 

Please help.

 

 

 

 

 

Please use plain text.
Developer
simon_hain
Posts: 15,805
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Adding a new mainscreen object as a child of the delegateManager of another MainScreen gives exception.

what functionality of a mainscreen do you need that cannot be done with a manager?

a mainscreen is intended to be a full screen, not a child of a manager.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: Adding a new MainScreen object as a child of the delegateManager of another MainScreen gives exception.

Unfortunately I believe this statement to incorrect:

 

Any object of type Field can be added to a manager, including other managers and screens If a manager or a screen is added to the current manager of a screen, they become child objects and behave as any other field.

 

The base of any Manager/Field hierarchy is a Screen, and it is my understanding that the BlackBerry will not accept anything for display that is not a screen and will not allow you to add a Screen to and Manager. 

 

This is not actually a restriction, since in fact every Screen has a base Manager associated with it.  If you wanted to move the contents of one Screen to another, you would just copy the contents of this Manager to another Manager (making sure to delete them from the original Manager first of course). 

 

I appreciate that this is not truly reflected in the way the classes are organized. 

Please use plain text.
Contributor
Napolean
Posts: 11
Registered: ‎11-28-2012
My Device: Curve 9320
My Carrier: Vodafone

Re: Adding a new MainScreen object as a child of the delegateManager of another MainScreen gives exception.

Thanks simon sir and peter sir

 

Sir I was trying to implement tabbed screen, that's why I was doing this.

 

There is an another way to implement tabs(using VerticalFieldManagers) that i did followed already.

 

I was trying to follow the above statement given in following BB article:
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800608/...

 

Main concern was:  will using Managers for creating tabs not create any problem in focus transfer between fields and click events on each field.

I am doing it will tell u if got any problem.

Please use plain text.
Developer
simon_hain
Posts: 15,805
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Adding a new MainScreen object as a child of the delegateManager of another MainScreen gives exception.

managers should be fine.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.