title: Pass data from dialog to activity Android
body: <p>I have problem.
  I made method which creates Dialog with my own layout. And I have no idea how to pass values (Strings) from my EdiText and asing to any variable in my Activity.
  In comments you can see how I was trying to solve this.</p>
  
  <p>Java method</p>
  
  <pre><code>public void makeDialog(){
          // custom dialog
          final Dialog dialog = new Dialog(context);
          dialog.setContentView(R.layout.dialog_ip);
          dialog.setTitle("IP connection");
  
  // Todo passing value from dialog to activity
  //        final EditText ipValueConnection = (EditText)findViewById(R.id.ipValueConnection);
  //        ipValueConnection.setOnClickListener(this);
  //        EditText portValueConnection = (EditText)findViewById(R.id.portValueConnection);
  //        Toast.makeText(context, ipValueConnection.getText().toString(), Toast.LENGTH_LONG).show();
  
          Button dialogButtonLogin = (Button) dialog.findViewById(R.id.dialogButtonLogin);
          // if button is clicked, close the custom dialog
          dialogButtonLogin.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
  
                  tryToConnect();
                  dialog.dismiss();
  
              }
          });
  
  
  
  
          // set the custom dialog components - text, image and button
  //        TextView text = (TextView) dialog.findViewById(R.id.IP);
  
          dialog.show();
  
      }
  </code></pre>
  
  <p>XML layout</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
      &lt;ImageView
          android:src="@drawable/antena"
          android:layout_width="220dp"
          android:layout_height="120dp"
          android:scaleType="centerInside"
          android:background="#FFFFBB33"
          android:contentDescription="@string/app_name"
          android:adjustViewBounds="true"
  
          /&gt;
      &lt;EditText
          android:id="@+id/ipValueConnection"
          android:inputType="textEmailAddress"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="16dp"
          android:layout_marginLeft="4dp"
          android:layout_marginRight="4dp"
          android:layout_marginBottom="4dp"
          android:hint="IP" /&gt;
      &lt;EditText
          android:id="@+id/portValueConnection"
          android:inputType="textPassword"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="4dp"
          android:layout_marginLeft="4dp"
          android:layout_marginRight="4dp"
          android:layout_marginBottom="16dp"
          android:fontFamily="sans-serif"
          android:hint="PORT"/&gt;
      &lt;Button
          android:id="@+id/dialogButtonLogin"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Login"
          android:layout_marginTop="5dp"
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>