Search code examples
androidonclickonclicklistenerandroid-button

Android button onClick is not getting triggered


All other things are working perfectly. only Button is not working. I also checked the id in declaration. it's same as in XML file. I add a Toast in onClick() for checking. But toast is not displayed in output. so onClick() in not working.


Solution

  • The reason why you are not seeing a Toast is because you never call show() on it. It has to look like this

    Toast.makeText(getContext(),"Btn Clicked",Toast.LENGTH_LONG).show();
    

    And besides that in Java you do not compare Strings with == but with the equals() method.