title: Passing String values from custom dialog to another activity
body: <p>A custom dialog is being used to take in user input, and then these values are being passed to another activity using <code>getter</code> methods. </p>
  
  <p>But when I pass the values to a method that outputs the string values to a <code>CSV</code> file, <code>shipName</code>, <code>analystName</code> etc the values appear as empty in the file like this, <code>" "</code> although I have entered the values in the dialog.</p>
  
  <p>I debugged the problem by watching the  String values in the debug menu's expression window, <code>shipName</code> and <code>analystName</code> but the values never update in the expression window.</p>
  
  <p>I gather from this that the method i which the input is being passed over is not correct.</p>
  
  <p>Does anyone know why the values being output are empty?</p>
  
  <p>This the dialog class being used:</p>
  
  <pre><code>package ie.gmi.computing;
  
  
  
  import android.annotation.SuppressLint;
  import android.app.AlertDialog;
  import android.app.Dialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.renderscript.Sampler;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class MyMessageDialog {
  
      private Context context;
      private EditText shipText, scientistNameText , scientistEmailText , volumeText , colourText ;
  
      private String shipString, scientistNameString , scientistEmailString , volumeString , colourString ;
  
  
  
      public AlertDialog displayMessage(Context context, String title, String message){
          AlertDialog.Builder builder = new AlertDialog.Builder(context);
          builder.setTitle(title);
          builder.setMessage(message);
          LayoutInflater inflater = LayoutInflater.from(context);
          final View v = inflater.inflate(R.layout.custom_view, null);
          builder.setView(v);
          shipText = (EditText)v.findViewById(R.id.shipNameEditText);
          scientistNameText = (EditText)v.findViewById(R.id.scientistEditText);
          scientistEmailText = (EditText)v.findViewById(R.id.emailEditText);
          volumeText = (EditText)v.findViewById(R.id.volumeEditText);
          colourText  = (EditText)v.findViewById(R.id.colourEditText);
          builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
  
  
  
              }
          });
          builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  dialog.cancel();
              }
          });
          AlertDialog dialog= builder.create();
          dialog.show();
          Button tb = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
          tb.setOnClickListener(new CustomListener(dialog));
  
          return dialog;
      }
  
  
      //getter/setters to allow access to string values
      //in SearchResult class
      public EditText getShipText() {
          return shipText;
      }
  
  
  
      public void setShipText(EditText shipText) {
          this.shipText = shipText;
      }
  
  
  
      public EditText getScientistNameText() {
          return scientistNameText;
      }
  
  
  
      public void setScientistNameText(EditText scientistNameText) {
          this.scientistNameText = scientistNameText;
      }
  
  
  
      public EditText getScientistEmailText() {
          return scientistEmailText;
      }
  
  
      public void setScientistEmailText(EditText scientistEmailText) {
          this.scientistEmailText = scientistEmailText;
      }
  
  
  
      public String getShipString() {
          return shipString;
      }
  
  
      public void setShipString(String shipString) {
          this.shipString = shipString;
      }
  
  
      public String getScientistNameString() {
          return scientistNameString;
      }
  
  
      public void setScientistNameString(String scientistNameString) {
          this.scientistNameString = scientistNameString;
      }
  
  
      public String getScientistEmailString() {
          return scientistEmailString;
      }
  
  
      public void setScientistEmailString(String scientistEmailString) {
          this.scientistEmailString = scientistEmailString;
      }
  
  
      public String getVolumeString() {
          return volumeString;
      }
  
  
      public void setVolumeString(String volumeString) {
          this.volumeString = volumeString;
      }
  
  
      public String getColourString() {
          return colourString;
      }
  
  
      public void setColourString(String colourString) {
          this.colourString = colourString;
      }
  
  
      public EditText getVolumeText() {
          return volumeText;
      }
  
  
  
      public void setVolumeText(EditText volumeText) {
          this.volumeText = volumeText;
      }
  
  
  
      public EditText getColourText() {
          return colourText;
      }
  
  
  
      public void setColourText(EditText colourText) {
          this.colourText = colourText;
      }
  
  
  
      @SuppressLint("NewApi")
      class CustomListener implements View.OnClickListener {
          private final Dialog dialog;
          public CustomListener(Dialog dialog) {
              this.dialog = dialog;
          }
          @SuppressLint("NewApi")
          @Override
          public void onClick(View v) {
  
  
              if(shipText.getText().toString().isEmpty() &amp;&amp; !shipText.getText().toString().equals(null)){
                  shipText.setError("The Field is required");
  
              }else if(scientistNameText.getText().toString().isEmpty() &amp;&amp; !scientistNameText.getText().toString().equals(null)){
                  scientistNameText.setError("The Field is required");
              }else if(scientistEmailText.getText().toString().isEmpty() &amp;&amp; !scientistEmailText.getText().toString().equals(null)){
                  scientistEmailText.setError("The Field is required");
              }else if(volumeText.getText().toString().isEmpty() &amp;&amp; !volumeText.getText().toString().equals(null)){
                  volumeText.setError("The Field is required");
              }else if(colourText.getText().toString().isEmpty() &amp;&amp; !colourText.getText().toString().equals(null)){
                  colourText.setError("The Field is required");
              }else{
                  shipText.setError(null);
                  scientistNameText.setError(null);
                  scientistEmailText.setError(null);
                  volumeText.setError(null);
                  colourText.setError(null);
  
  
                  shipString = shipText.getText().toString();
                  scientistNameString = scientistNameText.getText().toString();
                  scientistEmailString = scientistEmailText.getText().toString();
                  volumeString = volumeText.getText().toString();
                  colourString = colourText.getText().toString();
  
  
                  Toast.makeText(dialog.getContext(), "The Values you get from : " +
                          "\n Ship name value: " + shipText.getText().toString() +
                          "\n Scientist name value: " + scientistNameText.getText().toString() +
                          "\n email value: " + scientistEmailText.getText().toString() +
                          "\n sample volume value: " + volumeText.getText().toString() +
                          "\n sample colour value: " + colourText.getText().toString() , Toast.LENGTH_SHORT).show();
  
                  dialog.dismiss();
              }
          }
      }
  }
  </code></pre>
  
  <p>And this is how I'm retrieving the values in my SearchResult class, when i select the settings button:</p>
  
  <pre><code>public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
          case R.id.action_settings:
  
              MyMessageDialog dialog =new MyMessageDialog(); 
              dialog.displayMessage(SearchResult.this, "Sample Info", "Required");
  
  
  
              // store / use the values here
              shipName = dialog.getShipString();
              analystName = dialog.getScientistNameString();
              analystEmail = dialog.getScientistEmailString();
              sampleVolume = dialog.getVolumeString();
              sampleColour = dialog.getColourString();
              longitudeValue = String.valueOf(lng);
              latitudeValue = String.valueOf(lat);
              sampleMaterial = message;
  
              return true;
  
          default:
            return super.onOptionsItemSelected(item);
          } 
      } 
  </code></pre>