title: Android Input Dialog Return Input Value
body: <p>I'm pulling my hair out over this one.</p>
  
  <p>I have an app that when you press a menu item, I want it to show an input alert dialog. When the user taps "OK" then the text they've entered into the EditText in the dialog wants to be returned to be used later in the activity.</p>
  
  <p>So I thought putting:</p>
  
  <pre><code>name = input.getText().toString(); //input is an EditView which is the setView() of the dialog
  </code></pre>
  
  <p>Inside the onClick of the "Ok" button would work but it doesn't. Eclipse tells me I cant set name inside the onClick because it isn't final, but if I change name's definition to final it can't be changed obviously and so can't be set inside the onClick().</p>
  
  <p>Here is the full code for this bit: </p>
  
  <pre><code>String routeName = "";
  
          AlertDialog.Builder alert = new AlertDialog.Builder(this);  
  
          alert.setTitle("Title");  
          alert.setMessage("Message");  
  
          // Set an EditText view to get user input   
          final EditText inputName = new EditText(this);  
          alert.setView(inputName);  
  
          alert.setPositiveButton("Set Route Name", new DialogInterface.OnClickListener() {  
          public void onClick(DialogInterface dialog, int whichButton) {  
              routeName = inputName.getText().toString();  
            }  
          }); 
  
          alert.show();
  </code></pre>
  
  <p>I must be doing something really stupid here because I've googled around for ages and found no-one else with the same problem.</p>
  
  <p>Can anyone please enlighten me?</p>
  
  <p>Thank you for your time,</p>
  
  <p>InfinitiFizz</p>