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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Contributor
Posts: 2
Registered: ‎08-06-2012
My Device: simulator
My Carrier: none
Accepted Solution

Setting button label from user choice of an element of objectlistfield



I am a newbie and this is my first BB app. I have a problem and I tried to do this on my own, did quite a bit of research, but could not find any solution.

The thing is, I have a button added on main screen, by clicking this button I push a popupscreen on top of stack which contains an ObjectListField. Now I want to set the label of the button on the mainscreen as the name of the field selected in ObjectListField. I have attached my code on which I am experimenting and trying to learn(really enthusiastic about it Smiley Happy ),so would be grateful of any help in this regard. Thanks a ton Smiley Happy

package mypackage;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;

public final class MyScreen extends MainScreen
	ButtonField btn;
    public MyScreen()
        // Set the displayed title of the screen       
    	btn=new ButtonField("Label",ButtonField.CONSUME_CLICK);
    	btn.setChangeListener(new FieldChangeListener()
    		public void fieldChanged(Field field,int context){
    			UiApplication.getUiApplication().pushScreen(new mypopup());

    		/*public void inval(String lbl){
    		} */


class mypopup extends PopupScreen implements FieldChangeListener{
	String it;
ObjectListField obj=new ObjectListField(){
		public boolean navigationClick(int status,int time){
			int selectedindex=obj.getSelectedIndex();
			 it=(String)obj.get(obj, selectedindex);
		MyScreen my=new MyScreen();
	UiApplication.getUiApplication().invokeLater(new Runnable()
				public void run(){
			return true;		
	 public mypopup() {
		 super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR), Field.FOCUSABLE);
		 String[] type=new String[] {"a","b","c","d"};

	public void fieldChanged(Field field, int context) {
		// TODO Auto-generated method stub


Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Setting button label from user choice of an element of objectlistfield

welcome to the support forums.

what you do is to create a new screen instance, but what you want to do is to change the button on the existing one.
btw, all operations like setLabel, setText etc include invalidate, no need to call it manually.

you cannot access btn in your popup as it is in another class, so you have several options that i will explain to you using the Dialog class (which also offers a solution for what you want to achieve):

- use a listener, like http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/DialogClosedListe...
you register a listener from the screen on the popup, and it is called whenever something happens
- use a callback (give the popup your screen, or your button, or an interface that encapsulates it, basically). read about the pattern if you are not familiar with it
- you give your class a return method, like http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/Dialog.html#ask(j... java.lang.Object[], int)
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
New Contributor
Posts: 2
Registered: ‎08-06-2012
My Device: simulator
My Carrier: none

Re: Setting button label from user choice of an element of objectlistfield

Hi Simon, first of all thanks a ton for replying.

I learnt a lot by reading the documentation and links you gave me.


But the thing is, I really wanted to use popupscreen class instead of dialog. So (with some help) I did little changes in my code and it seems to work now.

I am writing changes in my code for other users who might have the same problem..

I created a method setlabel (*not to be confused with setLabel), in MyScreen class and right where I implement popscreen in mypopup class, I did..


Screen scr = UiApplication.getUiApplication().getActiveScreen();
            if (scr instanceof MyScreen) {
                MyScreen my = (MyScreen) scr;


it finally seems to work now.


Cheers Smiley Happy