Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can anyone illustrate the return of "onOptionsItemSelected"?

Tags:

android

return

in android development site, i saw the explanation of onOptionsItemSelected, on the return side, it said that: boolean Return false to allow normal menu processing to proceed, true to consume it here.

Sorry for my dumb, can anyone illustrate what the sentence is explaining, should i return true or false in the normal situation?

like image 793
Searene Avatar asked Feb 03 '12 10:02

Searene


2 Answers

You should return true if you process the menu item and return super.onOptionsItemSelected(item) if you don't.

e.g.

public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
        case R.id.option1:
            handleOption1();
            return true;
        case R.id.option2:
            handleOption2();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
like image 117
mcnicholls Avatar answered Oct 27 '22 00:10

mcnicholls


I think you can just let the system handle it by doing :

return super(...);

Else, the return TRUE/FALSE just means that if the case you are treating has fully handled the event just return TRUE. If thats not the case then return false, and system should be dispatching the even to the right handler.

like image 33
Cehm Avatar answered Oct 27 '22 01:10

Cehm