Note that there are some explanatory texts on larger screens.

plurals
  1. POBlackberry: select item in a list, return to previous screen
    primarykey
    data
    text
    <p>I have prepared a very short test case (s. below) for my question.</p> <p>On a button click I would like to display a list of strings in a new screen. </p> <p>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.</p> <p><img src="https://i.stack.imgur.com/cfVmM.png" alt="screenshot"></p> <p>My 2 problems are:</p> <ol> <li>From inside the menu I don't know how to pop the currently displayed screen</li> <li>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)</li> </ol> <p>Please suggest the necessary changes for my <strong>src\mypackage\MyList.java</strong>:</p> <pre><code>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 &lt; 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? } }; } </code></pre> <p>Thank you! Alex</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload