Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a simple yes/no dialog box in a view (Android)
    primarykey
    data
    text
    <p>I've got an onCreateDialog method in my activity, which has a case switch to bring up different dialogs that I want to display depending on the request.</p> <p>I cannot use the showDialog() method from my view because it's not accessible from the context that is passed when the view is created. At least, I can't find a way to access it.</p> <p>How do I use showDialog from my application's view? Do I need to create a listener? And if so, how? Is there a better method?</p> <p>Here is my onCreateDialog code that exists in my application's activity:</p> <pre><code>protected Dialog onCreateDialog(int id) { AlertDialog alert=null; switch(id) { case DIALOG_GAMEOVER_ID: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("You died. Play again?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //init(); //oGameState = eGameState.PLAYING; dialog.cancel(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }); alert = builder.create(); break; default: break; } return alert; } </code></pre> <p>I tried passing a reference to my activity, and I get crashes. Perhaps I am doing it wrong?</p> <p>In my activity:</p> <pre><code> // set our MainView as the View oNebulaMainView = new NebulaMainView(this, this); setContentView(oNebulaMainView); </code></pre> <p>In my view:</p> <pre><code>public NebulaMainView(Context context, Activity oActivity) { super(context); // adding the callback (this) to the surface holder to intercept events getHolder().addCallback(this); // create the game loop thread thread = new NebulaMainThread(getHolder(), this); setFocusable(true); oActivity.showDialog(DIALOG_GAMEOVER_ID); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload