0

I'm trying to define an onClick handler method in an XML layout for buttons in a Dialog but the app crashes when the buttons are clicked due to NoSuchMethodException (it can't find the method). The method signature is public void searchMovies(View) and I can guarantee that it is spelled consistently in the XML file and in code. This similar question provides a solution by putting the putting the method into the Activity that the Dialog belongs to, but that doesn't work for me.

However, I'm using a FragmentActivity and FragmentStatePagerAdapter, so maybe this is the reason it doesn't work for me? I've tried putting the method into the FragmentActivity, the FragmentStatePagerAdapter, the Fragment and also the anonymous OnClickListener class that handles launching the Dialog. None of them have worked, all give NoSuchMethodException error. Again, I can guarantee that the method is spelled correctly/consistently.

I know that I can do this programmatically, but it would be much more convenient if I could do it the other way. Is it possible? Thanks.

Community
  • 1
  • 1
RTF
  • 6,214
  • 12
  • 64
  • 132
  • If I have not misunderstood you, the best way to achieve it, in my opinion, is to subclass `Dialog/DialogFragment` and add the method your subclass. I am assuming the the layout with the onClick property is the custom view for your dialog. – Blackbelt Jan 30 '14 at 13:57
  • "I am assuming the layout..." => yes, that's right. I'll give what you're suggesting a go. – RTF Jan 30 '14 at 14:15
  • 1
    Adding the method to my new Dialog subclass did not work. However, adding the method to the FragmentActivity, as well as using the Dialog subclass is working. This is actually the whole solution set out in the other question referenced in my question. I just wasn't implementing it properly. Anyway, that's the way to go. Thanks for the help @blackbelt – RTF Jan 30 '14 at 14:40

1 Answers1

0

As I said in the comments above, this is the solution (I suppose this is a duplicate, then, but I reckon it still might be useful to someone looking for the solution. I don't mind if someone feels that it should be deleted though).

Community
  • 1
  • 1
RTF
  • 6,214
  • 12
  • 64
  • 132