android DialogFragment android:onClick=“buttonCancel” causes IllegalStateException could not find a method

后端 未结 3 1564
我寻月下人不归
我寻月下人不归 2021-02-10 15:12

I have a problem with my Dialog Fragment. I wanted to use android:onClick attribute as in my opinion code is more clear then.

In my layout I have the following declarati

3条回答
  •  孤街浪徒
    2021-02-10 15:25

    I don't think that is related to the support fragment.

    The issue seems to arise from the fact that you are registering a onClick on XML that fires up based on the activity that the fragment was binded at the time of the click.

    As your "buttonCancel" method does not exists in the activity (because it is inside the fragment), it fails.

    I don't think that really is a desirable solution, but you can register your "buttonCancel" method on your activity for that error to go away, and make that "buttonCancel" method registered on the activity only call the method that exists in the fragment, in case you want to keep your action / view behaviour inside the fragment.

提交回复
热议问题