OnClick of an image I am popping up a screen which has dropdown code, where I have to select the data and pass it to the screen from where it was popped up, after selecting the data from the dropdown the popupscreen should disappear passing the selected ocf value to the firstscreen. I am not able to hide the popupscreen after selection and am not able to pass the data back to the first screen
This code will call a popup screen
if (field==bitmapField1) {
UiApplication.getUiApplication().pushScreen(new MyPopup());
}
This is the popped up screen
public class MyPopup extends PopupScreen {
ObjectChoiceField ocf;
public MyPopup() {
super(new VerticalFieldManager(), Field.FOCUSABLE);
// this listener 'listens' for any event (see at the bottom)
FieldListener listener = new FieldListener();
TimeZone[] zone = TimeZoneUtilities.getAvailableTimeZones();
ocf = new ObjectChoiceField("Set Timezone", zone);
ocf.setChangeListener(listener);
add(ocf);
}
class FieldListener implements FieldChangeListener {
public void fieldChanged(Field f, int context) {
if (f == ocf) {
Object ob = ocf.getChoice(ocf.getSelectedIndex());
String str = ob.toString();
Dialog.alert(str);
}
}
}
}
You should add an attribute to your PopUpScreen that references the Screen that launched the PopUp. That way, you can send parameters to the parent Screen without problems:
public class MyPopup extends PopupScreen {
ObjectChoiceField ocf;
MainScreen parentScreen;
public MyPopup(MainScreen parentScreen) {
this.parentScreen = parentScreen;
...
And when you launch the PopUp:
if(field==bitmapField1){
UiApplication.getUiApplication().pushScreen(new MyPopup(this));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With