Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to navigate in a circle
    primarykey
    data
    text
    <p>the title might be not very descriptive but i couldn't think of a better one.</p> <p>The problem is as follows: I have one screen (ScreenOne) with a link to another screen (ScreenTwo). On the ScreenTwo is a link back to ScreenOne.</p> <p>I implemented this via custom RichTextFields and a custom ChangeListener.</p> <p>Now the problem is that i keep getting a StackOverflowError! Is there any way to navigate back and forth in that way?</p> <p>regards matt</p> <pre><code>public class MyApp extends UiApplication { public static void main(String[] args) { MyApp theApp = new MyApp(); theApp.enterEventDispatcher(); } public MyApp() { ScreenOne so = ScreenProvider.getInstance().getScreenOne(); so.initialize(); ScreenProvider.getInstance().getScreenTwo().initialize(); pushScreen(so); } } public class ScreenOne extends MainScreen { MyTextField link; public ScreenOne() { link = new MyTextField("FirstScreen"); add(link); } public void initialize(){ link.setChangeListener((FieldChangeListener) new MyFieldChangeListener(ScreenProvider.getInstance().getScreenTwo())); } } public class ScreenTwo extends MainScreen { MyTextField link; public ScreenTwo() { link = new MyTextField("SecondScreen"); add(link); } public void initialize(){ link.setChangeListener((FieldChangeListener) new MyFieldChangeListener(ScreenProvider.getInstance().getScreenOne())); } } public class MyFieldChangeListener implements FieldChangeListener { private Screen nextScreen; public MyFieldChangeListener(Screen nextScreen) { this.nextScreen = nextScreen; } public void fieldChanged(Field field, int context) { UiApplication.getUiApplication().pushScreen(nextScreen); } } public class MyTextField extends RichTextField { public MyTextField() { super(); } public MyTextField(String text) { super(text); } protected boolean touchEvent(TouchEvent message) { if (TouchEvent.CLICK == message.getEvent()) { FieldChangeListener listener = getChangeListener(); if (null != listener) listener.fieldChanged(this, 1); } return super.touchEvent(message); } } public class ScreenProvider { private static ScreenProvider instance = null; private ScreenProvider(){} public static ScreenProvider getInstance() { if (instance == null) { instance = new ScreenProvider(); } return instance; } private ScreenOne screenOne = new ScreenOne(); private ScreenTwo screenTwo = new ScreenTwo(); public ScreenOne getScreenOne() { return screenOne; } public ScreenTwo getScreenTwo() { return screenTwo; } } </code></pre>
    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.
    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