Office Hours — Today, April 2

Thursday, March 31

Apr 2
3:50 PM
Mark M.
has entered the room
3:55 PM
Mark M.
turned on guest access
4:45 PM
Steve S.
has entered the room
Mark M.
hello, Steve!
Steve S.
Hi Mark!
Mark M.
how can I help you today? (in the remaining ~10 minutes)
4:50 PM
Steve S.
Let me upload my question.
View paste
I want to use the same DialogFragment subclass in multiple cases.
For what I need to do, this would require having different onClickListeners in different cases. I'm trying to figure out how to do this.

For other data types (e.g. String, int), I know I can pass them into the DialogFragment using a newInstance() method on the DialogFragment subclass, and then store them in a bundle for later use.

Can I do this for onClickListeners? Is there a better way I can accomplish what I'm trying to do (use different onClickListeners in different cases for the same DialogFragment subclass)?
Mark M.
"Can I do this for onClickListeners?" -- no
Steve S.
ok
Mark M.
"Is there a better way I can accomplish what I'm trying to do" -- have one OnClickListener, that calls a method on the hosting activity, that does whatever needs doing
use an interface if there may be several hosting activities
include some sort of flag or token to indicate "hey, this is the sort of thing you should be doing!"
as simple integers, strings, and stuff can be put in the arguments Bundle
Steve S.
Ok. So I might use the stuff that can be passed into the bundle as a way to identify which onClickListener should be used?
Mark M.
right
Steve S.
Ok. I'll look into doing that.
I know your time is about up, so I'll leave it at that.
Mark M.
either that, or organize your DialogFragment to make it trivial to create a simple subclass that overrides some onClick()-ish method
and use those subclasses
that's out of scope of your original request, but it's a more OO approach to the problem
Steve S.
Right. I'll look into that as well.
4:55 PM
Steve S.
I appreciate your help. Thank you so much and have a good day!
Mark M.
you too!
Steve S.
has left the room
5:00 PM
Mark M.
turned off guest access

Thursday, March 31

 

Office Hours

People in this transcript

  • Mark Murphy
  • Steve S.