This question is about the concept of what I am attempting to code.
I Have an Activity
“public class Board extends Activity {”
which has “setContentView(myBoard)” where myBoard is an instance of
“class NewBoard extends View implements OnTouchListener{”
NewBoard draws graphics with onDraw and also draws graphical buttons.
A click on a button called “Solve” makes a call to another class
“public class SKO {” which has no visual componants and does a calcuation, the results of which are redrawn by the graphic view.
This all works well.
I now want to call a Dialog from more graphically drawn buttons on the NewBoard View.
In the “top” class – Board, I have suitable code in
“protected Dialog onCreateDialog(int id) {”
I know this code is good because if I add a showDialog(int),(an Alertdialog with a cancel button) to the onCreate of Board,then on running the class Board, the dialog comes up, and when cancelled, my graphics are working underneath.
My problem is ****
that I can’t find a way to call the showDialog(int) within Board from my graphics View (NewBoard).
I have tried adding the “protected Dialog onCreateDialog(int id) {” to my graphics View (NewBoard) but I believe it can only be added to an activity.
I would very much appreciate some advice.
I would suggest that you define a Listener interface like NewBoardListener (not a great name, but good enough for an example). Your Board class can register with your NewBoard view as a NewBoardListener. Let’s assume the button event in your NewBoard view has something to do with “View Status” then your NewBoardListener interface can define a method called something like onViewStatus(). When the user taps the button on the NewBoard view, you make a callback to your newBoardListener.onViewStatus(). Then in your Board class which implements the NewBoardListener interface, in your onViewStatus method, you call showDialog(int).