Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Getting Data from an Intent

aneesh kumar
aneesh kumar
1,426 Points

not entering name in the name field

I tried not entering data of any sort in the name field of the app. The app proceeded to the next story line and showed Hello World!. Is it possible to make sure we get a user input before we proceed??

2 Answers

Logan R
Logan R
22,989 Points

On the listener for the button (or what ever listener event that happens to change to the next screen), do an if statement and check to see if the text field is not blank.

onButtonClick(e -> {

    if(!textField.equals("")) {
        // Go to next Screen
    } else {
        // Tell use that the info is blank. Maybe toast?
    }

});

Hope this helps!