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 a Self-Destructing Message Android App Sending Messages Adding a Send Button

James N
James N
17,864 Points

my onOptionsItemSelected is COMPLETLEY different from the one ben uses (it has no case home blah blah blah)

my onOptionsItemSelected is COMPLETLEY different from the one ben uses (it has no case home blah blah blah)

so I don't know how to continue on in this. I will need help this project was created on a beta version of android studio but I am now using 1.0.1 my code for onOptionsItemSelected:

OnOptionsItemSelected.java
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) { // I have an if statement instead of a case home thingy
            return true;
        }


        return super.onOptionsItemSelected(item);
    }

do I just do

PossibleSolution.java
// if statement above
else if (id == R.id.action_send) {
    return true;
}

after the if statement?

2 Answers

James N
James N
17,864 Points

EDIT: I just tried adding the else if statement, I don't seem to be getting any problems... Ill let you know after I watch the next video and will see if there is any problems,

Damien Watson
Damien Watson
27,419 Points

In case someone else comes across this, I have the same code, but in the video Ben removed the 'action_settings' so this was throwing an error for me, so I just repurposed that if statement for the send, so (with comments removed) :

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_send) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }