Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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);
    }