InflateException: Couldn't resolve menu item onClick handler

后端 未结 7 786
情书的邮戳
情书的邮戳 2020-12-08 19:12

I asked this question 6 years ago. In the meantime Android development best practices have changed, and I have become a better developer.

Since then, I have realized

7条回答
  •  一向
    一向 (楼主)
    2020-12-08 19:59

    I found a solution that worked for me. Usually the onClick attribute in a layout has the following method

    public void methodname(View view) { 
        // actions
    }
    

    On a menu item (in this case Sherlock menu) it should follow the following signature:

    public boolean methodname(MenuItem item) { 
        // actions
    }
    

    So, your problem was that your method returned void and not boolean.

提交回复
热议问题