I have a custom class that extends a View, where I draw some geometric objects on the canvas. I also have a dialog class where I display a simple dialog. (FinePartita.java)
My MainActivity.java (from where I call my View)
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
PaschiPongView ppv = new PaschiPongView(getApplicationContext());
setContentView(ppv);
}
}
PaschiPongView.java
public class PaschiPongView extends View {
// a lot of code here
}
FinePartita.java (the example is from Google)
public class FinePartita extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.doUreallyWantToExit)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
The problem is, I need to display the dialog in my PaschiPongView class, but I can't do it because it needs a FragmentManager and since my class extends a View, it doesn't have it.
I can't call it like this:
FinePartita test = new FinePartita();
test.show(getFragmentManager(), "dialog"); // doesn't work
Any suggestions would be appreciated.