Should “android: onOptionsItemSelected” return true or false

后端 未结 5 540
情话喂你
情话喂你 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:24

    The problem with your method is that you return true even if your switch statement does not find an item. If you return true immediately like the other method for each switch case, then you can assume, if you are at the end of the method, that no switch cases were found, so return false to show that it was not handled.

提交回复
热议问题