Should “android: onOptionsItemSelected” return true or false

后端 未结 5 541
情话喂你
情话喂你 2020-12-07 20:59

In onOptionsItemSelected... I saw some code that are different in the switch block.

Case 1 (Normally seen)

public boolean onOptionsI         


        
5条回答
  •  生来不讨喜
    2020-12-07 21:15

    When I used Android Studio to generate a generic app, the template code for onOptionsItemSelected() returns true if item consumed otherwise it passes the call onto the super class.

    @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_mymenuaction) {
            return true;
        }
    
        return super.onOptionsItemSelected(item);
    }
    

提交回复
热议问题