Starting another Screen

Respond to the Button

Add the button listener in the HelloNeomadScreen.java

  • attach a ClickListener to the Button
  • implement the ClickListener class
  • fill the onClick method
public final class HelloNeomadScreen extends Screen implements ClickListener {

        protected void onCreate() {
                // Fill the screen with the HELLOWORLD_SCREEN layout
                setContent(Res.layout.WELCOME_SCREEN);

                // Attach ClickListener to buttons
                Button goButton = (Button) findView(Res.id.button_welcome_go);
                goButton.setClickListener(this);
        }

        public void onClick(View view) {
                switch (view.getId()) {
                        case Res.id.button_welcome_go:
                                clickWelcomeGo();
                                break;

                        default:
                                break;
                }
        }

        private void clickWelcomeGo() {
                // Do something in response to welcome button
        }
}

When the user clicks over the button the clickWelcomeGo method will be invoked.

private void clickWelcomeGo() {
        // will show another screen over the current screen
        controller.pushScreen(DisplayScreen.class);
}

Create the second Screen

Create the screen

Create the DisplayScreen.java

package com.myapp.helloneomad;

import com.neomades.app.Screen;

public final class DisplayScreen extends Screen {

        protected void onCreate() {
                setContent(Res.layout.DISPLAY_SCREEN);
        }
}

Declare User interface in XML

Create the UI display_screen.xml

<?xml version="1.0"?>
<VerticalLayout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://www.neomades.com/XSD/4.0.0/layout.xsd"
        stretchHorizontalMode="MATCH_PARENT"
        stretchVerticalMode="MATCH_PARENT"
        contentAlignment="HCENTER|VCENTER">

<!-- A TextLabel allows to display a simple text on the screen.
We want the TextLabel size to match the text. -->
<TextLabel
        stretchHorizontalMode="MATCH_CONTENT"
        stretchVerticalMode="MATCH_CONTENT"
        text="@string/DISPLAY_SCREEN" />

</VerticalLayout>
  • Add the string resource inside the strings-en.xml
<?xml version="1.0" encoding="utf-8"?>
<strings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.neomades.com/XSD/4.0.0/strings.xsd">
    <string name="WELCOME_SCREEN">Greeting</string>
    <string name="WELCOME_GO">GO</string>
    <string name="DISPLAY_SCREEN">Display screen</string>
</strings>