Button click in Android Fragment does not work

后端 未结 3 1847
终归单人心
终归单人心 2021-01-22 15:09

activity_main.xml



        
相关标签:
3条回答
  • 2021-01-22 15:48

    The way XML onClick is implemented is directed to Activities, not Fragments. The activity should own the btnClick1 method, not a fragment.

    0 讨论(0)
  • 2021-01-22 15:55

    Since others have addressed setting onClick listener, let me add that if you have done so, and still getting the error check permissions required. For my case, the item on fragment was meant to open chat which requires microphone so it was not working until I added appropriate permissions in Manifest file.

    0 讨论(0)
  • 2021-01-22 15:56

    You need to assign OnClickListener in fragment code to make it work. See Snicolas answer for the "why".

    0 讨论(0)
提交回复
热议问题