Note that there are some explanatory texts on larger screens.

plurals
  1. POGet field value from PopupScreen back to MainScreen in Blackberry
    text
    copied!<p>Now i have a MyScreen which extends from MainScreen containing a button. When the button clicked, it will show the PopupScreen containing list of RadioButtonFields, OK and Cancel buttons. My question is how to get RadioButtonField value from PopupScreen back to MyScreen.</p> <p>Please help me in this case.</p> <p>Thanks</p> <hr> <p>Below is my code</p> <p><strong>MyScreen.java</strong></p> <pre><code>public class MyScreen extends MainScreen{ private int currentValue = 0; public MyScreen() { LabelField lblField = new LabelField(); lblField.setText("Current Value = " + currentValue); ButtonField btnPopup = new ButtonField("Show Popup"); btnPopup.setChangeListener(new FieldChangeListener() { public void fieldChanged(Field field, int context) { UiApplication.getUiApplication().pushScreen(new MyPopupScreen()); } }); add(lblField); add(btnPopup); } } </code></pre> <p><strong>MyPopupScreen</strong></p> <pre><code>public class MyPopupScreen extends PopupScreen implements FieldChangeListener { private int currentValue = -1; public MyPopupScreen() { super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR), Field.FOCUSABLE ); add(new LabelField("Select Chart Type")); RadioButtonGroup radioGroup = new RadioButtonGroup(); for (int i = 0; i &lt; 10; i++) { RadioButtonField radio = new RadioButtonField("Option no. " + i, radioGroup, false); radio.setChangeListener(this); add(radio); } ButtonField cancelBtn = new ButtonField("Close"); ButtonField okBtn = new ButtonField("OK"); add(okBtn); add(cancelBtn); cancelBtn.setChangeListener(new FieldChangeListener() { public void fieldChanged(Field field, int context) { UiApplication.getUiApplication().popScreen(); } }); okBtn.setChangeListener(new FieldChangeListener() { public void fieldChanged(Field field, int context) { //How to get radio value or index value to pass back to MyScreen } }); } public void fieldChanged(Field field, int context) { if (field instanceof RadioButtonField) { RadioButtonField radio = (RadioButtonField) field; currentValue = radio.getIndex(); } } } </code></pre>
 

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