Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4600796
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:44:06+00:00 2026-05-21T23:44:06+00:00

I have prepared a very short test case (s. below) for my question. On

  • 0

I have prepared a very short test case (s. below) for my question.

On a button click I would like to display a list of strings in a new screen.

After the user selects one item in the list, the previous screen should be displayed again and the button label should be set to the selected string.

screenshot

My 2 problems are:

  1. From inside the menu I don’t know how to pop the currently displayed screen
  2. How to pass the selected item from one screen to another (assuming I don’t want to introduce a public variable/method on the former screen as a workaround)

Please suggest the necessary changes for my src\mypackage\MyList.java:

package mypackage;

import java.util.*;
import net.rim.device.api.collection.*;
import net.rim.device.api.collection.util.*; 
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.util.*;
import net.rim.device.internal.i18n.*;

public class MyList extends UiApplication implements FieldChangeListener {
    MyScreen myScreen = new MyScreen();

    public static void main(String args[]) {
        MyList app = new MyList();
        app.enterEventDispatcher();
    }

    public MyList() {
        MainScreen titleScreen = new MainScreen();
        titleScreen.setTitle("Click the button:");

        // TODO change the label of this button (see below)
        ButtonField myButton = new ButtonField("Show the list", ButtonField.CONSUME_CLICK);
        myButton.setChangeListener(this);
        titleScreen.add(myButton);

        pushScreen(titleScreen);
    }

    public void fieldChanged(Field field, int context) {
        pushScreen(myScreen);
    }
} 

class MyScreen extends MainScreen {
    ObjectListField myList = new ObjectListField();

    public MyScreen() {
        setTitle("Select an item below:");

        myList.set(new String[] { "Item 1", "Item 2", "Item 3", "Item 4", }); 
        add(myList);

        addMenuItem(myMenu);
    }

    private final MenuItem myMenu = new MenuItem("Select item", 0, 0) {
        public void run() { 
            int index = myList.getSelectedIndex();
            if (index < 0)
                return;

            String item = (String) myList.get(myList, index);
            Status.show("Selected: " + item);

            // TODO how to return to the previous screen here?
            // TODO how to call myButton.setLabel(item) here?
        }
    };
}

Thank you!
Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:44:07+00:00Added an answer on May 21, 2026 at 11:44 pm

    Use a callback pattern:

    class TitleScreen extends MainScreen {
    
        private ButtonField myButton;
    
        public TitleScreen() {
            super();
            setTitle("Click the button:");
    
            // TODO change the label of this button (see below)
            myButton = new ButtonField("Show the list", ButtonField.CONSUME_CLICK);
            myButton.setChangeListener(new FieldChangeListener() {
                public void fieldChanged(Field field, int context) {
                    OnItemSelectedCallback callback = 
                            new OnItemSelectedCallback() {
                        public void onItemSelected(String label) {
                             TitleScreen.this.onItemSelected(label);
                        }
                    };
                    MyScreen myScreen = new MyScreen(callback);
                    UiApplication.getUiApplication().pushScreen(myScreen);
                }
            });
            add(myButton);
        }
    
        private void onItemSelected(String label) {
            // this will be called when a menu item is executed on the MyScreen
            // e.g. you can call smth like: myButton.setLabel(label);
        }
    }
    
    interface OnItemSelectedCallback {
        void onItemSelected(String label);
    }
    
    class MyScreen extends MainScreen {
        ObjectListField myList = new ObjectListField();
    
        private final OnItemSelectedCallback onItemSelectedCallback;
    
        public MyScreen(OnItemSelectedCallback onItemSelectedCallback) {
            setTitle("Select an item below:");
    
            this.onItemSelectedCallback = onItemSelectedCallback;
    
            myList.set(new String[] { "Item 1", "Item 2", "Item 3", "Item 4", }); 
            add(myList);
    
            addMenuItem(myMenu);
        }
    
        private final MenuItem myMenu = new MenuItem("Select item", 0, 0) {
            public void run() { 
                int index = myList.getSelectedIndex();
                if (index < 0)
                    return;
    
                String item = (String) myList.get(myList, index);
                Status.show("Selected: " + item);
    
                // TODO how to return to the previous screen here?
                // TODO how to call myButton.setLabel(item) here?
    
                // notify the parent screen
                onItemSelectedCallback.onItemSelected(item);
    
                // close the current screen
                UiApplication.getUiApplication().popScreen(MyScreen.this);
            }
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very general question and have prepared a simple test case. When
I have a pure ActionScript 3 problem, but the simplified test case I've prepared
We have a Prepared Statement in Java and we hear that it is different
I Have a prepared statement INSERT INTO mst(time) VALUES (?); where time is of
I have heard that prepared statements with SQLite should improve performance. I wrote some
Is it possible to have a MySQLi prepared statement within the fetch() call of
I have my application designed with Repository pattern implemented and my code prepared for
I have a function that I use called sqlf(), it emulates prepared statements. For
The JDBC 3.0 spec talks about Connection (and Prepared Statement) pooling. We have several
We have a couple of very very slow JUnit tests that make heavy use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.