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
New Developer
Posts: 8
Registered: ‎12-16-2009
My Device: Not Specified

Help with Screens

Hi

 

I'm wondering how I should be sending information between two screens.  eg. if I wanted to get a String from the ContactsScreen and pass it back to ComposeScreen.

 

Thanks in advance for any advice you can give me.

 

kentt

 

 

 

 

/*
 * MyApp.java
 */

package my.pack;

import net.rim.blackberry.api.mail.Address;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.AutoTextEditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class MyApp extends UiApplication
{
	private AutoTextEditField messageField;
	public static ComposeScreen _composeScreen;
	
	public static void main (String args[])
	{		
		MyApp app = new MyApp();
		app.enterEventDispatcher();
	}
	
	public MyApp()
	{
		//display a new screen
		_composeScreen = new ComposeScreen(null);
		pushScreen(_composeScreen);
	}
	
	public class ComposeScreen extends MainScreen 
    {
		ContactsScreen _contactsScreen = new ContactsScreen();
		public ComposeScreen(Address[] toList) 
		{
			super();
			
			// make/display title
			LabelField title = new LabelField("My App");
			setTitle(title);
			
			//create message field
			messageField = new AutoTextEditField("","");
			add(messageField);
			
			addMenuItem(_contactsItem);
			
		}	
		
		public MenuItem _contactsItem = new MenuItem("Add Recipient",110,10)
		{
			public void run()
			{
				_contactsScreen = new ContactsScreen();
				UiApplication.getUiApplication().pushScreen(_contactsScreen);
			}
		};
    }
	

}

 

/*
 * ContactsScreen.java
 * 
 */

package my.pack;

import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.AutoTextEditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;

public final class ContactsScreen extends MainScreen
{
	private AddContact addContact;
	private class AddContact extends MenuItem
	{
		public AddContact()
		{
			super("Add contact",100000,10);
		}
		public void run()
		{
			
		}
	}
	
	public ContactsScreen()
	{
		addContact = new AddContact();
		setTitle(new LabelField("Contacts",LabelField.ELLIPSIS|LabelField.USE_ALL_WIDTH));
		AutoTextEditField name = new AutoTextEditField("Name: ", " ");
		add(name);
		
	}
	
	protected void makeMenu(Menu menu, int instance)
	{
		menu.add(addContact);
		super.makeMenu(menu, instance);
	}
	
}

 

 

Highlighted
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Help with Screens

[ Edited ]

You can implement a setContactName(String name) in your ContactsScreen class.

 

Then your code would be:

 

screen = new ContactsSceen()

 

screen.setContactName(someName)

 

In your ContactsScreen class:

 

private String contactName;

 

public void setContactName(String contactName)

{

    this.contactName = contactName;

}