Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn/save values from AlertDialog in Android?
    primarykey
    data
    text
    <p>So, I've got this code for an AlertDialog in an Android activity, and although it works and pops up at the correct moment, when I press the "OK" buttons it's supposed to save the 2 variables which I put in, into 2 Strings which after the activity should be able to use those strings. </p> <pre><code>private void showDialog(){ AlertDialog.Builder alertdg = new AlertDialog.Builder(this); alertdg.setTitle("Choose page"); alertdg.setMessage("Choose episode/page"); final EditText page = new EditText(this); final EditText episode = new EditText(this); page.setWidth(210); episode.setWidth(210); LinearLayout layout = new LinearLayout(this); layout.addView(episode); layout.addView(page); alertdg.setView(layout); alertdg.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub episodeString = episode.getText().toString(); pageString = page.getText().toString(); } }); alertdg.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); alertdg.show(); } </code></pre> <p>And yes if you're wondering I already declared the 2 strings "episodeString" and "pageString" somewhere in the start of the activity, and I know I declared them correctly. Now what I'm wondering is, why can't I return those values so that the rest of the activity can use them? I've tried many times but the Dialog just won't return/save values... What am I doing wrong?</p>
    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