title: Dialog + callback?
body: <p>I have made a CustomTypeDialog class and what I want is to use EditText which is not in the active layout. I get a nullpointer exception when I try to click one of the buttons, which I think is because they are not in the active layout. Can you help me solve this? The dialog is called in an activity from another class. </p>
  
  <pre><code>package dk.droidrun.droidrunapp;
  
  import android.app.Dialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ImageButton;
  
  public class CustomTypeDialog extends Dialog {
      ImageButton routeType;
      EditText txtType;
      Button imageRun, imageBike, imageWalk;
      public CustomTypeDialog(final Context context) {
          super(context);
  
          this.setContentView(R.layout.customtype_dialog);
          routeType = (ImageButton)findViewById(R.id.saveRoute_activityType);
          txtType = (EditText)findViewById(R.id.saveRoute_typeTxt);
          imageRun = (Button)findViewById(R.id.dialog_btn1);
          imageBike = (Button)findViewById(R.id.dialog_btn2);
          imageWalk = (Button)findViewById(R.id.dialog_btn3);
  
          setTitle("Select activity type");
          show();
          imageRun.setOnClickListener(new View.OnClickListener() {    
              @Override
              public void onClick(View v) {
                  txtType.setText("Run");
                  routeType.setBackgroundResource(R.drawable.track_run);
              }
          });
  
          imageBike.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  txtType.setText("Bike");
                  routeType.setBackgroundResource(R.drawable.track_bike);
              }
          });
  
          imageWalk.setOnClickListener(new View.OnClickListener() {       
              @Override
              public void onClick(View v) {
                  txtType.setText("Walk");
                  routeType.setBackgroundResource(R.drawable.track_walk);
              }
          });
      }
  
  } 
  </code></pre>
  
  <p>This is my customtype_dialog.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".AutoMode"
      android:background="@color/black" &gt;    
  
  &lt;RelativeLayout 
      android:id="@+id/dialog_relativeLayout1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_margin="3dp"    
      android:layout_above="@+id/dialog_relativeLayout2"
      android:layout_centerHorizontal="true" &gt;
  
      &lt;Button
          android:id="@+id/dialog_btn1"
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:layout_margin="3dp"
          android:background="@drawable/track_run"
          android:layout_alignRight="@+id/dialog_relativeLayout1"
          android:layout_alignTop="@+id/dialog_relativeLayout1"
          /&gt;
  
      &lt;Button 
          android:id="@+id/dialog_btn2"
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:layout_margin="3dp"
          android:background="@drawable/track_bike"
          android:layout_alignTop="@+id/dialog_relativeLayout1"
          android:layout_toRightOf="@+id/dialog_btn1"
          /&gt;
  
      &lt;Button 
          android:id="@+id/dialog_btn3"
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:layout_margin="3dp"
          android:layout_toRightOf="@+id/dialog_btn2"
          android:background="@drawable/track_walk"
          /&gt;
   &lt;/RelativeLayout&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>saveroutes.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="@color/black"
      tools:context=".SaveRouteActivity" &gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:layout_marginTop="20dp"
          android:text="@string/saveRoute"
          android:textColor="@color/white"
          android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
     &lt;TextView
          android:layout_marginTop="10dip"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="#7a0100"
          android:text="Enter a name for the route" /&gt; 
  
      &lt;EditText
          android:id="@+id/saveRoute_nameRoute"
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:layout_gravity="center"        
          android:ems="10"
          android:hint="@string/saveRoute_name" 
          android:textColor="@color/white" 
          android:background="#4e4751"      
          android:inputType="textPersonName" &gt;
      &lt;/EditText&gt;
  
      &lt;TextView        
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="#7a0100"
          android:text="Describe your route" /&gt;
  
      &lt;EditText
          android:id="@+id/saveRoute_desciptionTxt"
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:ems="10"
          android:hint="@string/saveRoute_description"
          android:textColor="@color/white"
          android:background="#4e4751"    
          /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textColor="#7a0100"
          android:text="Activity type (e.g. running)"
           /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"       
          android:orientation="horizontal"
          android:gravity="center_horizontal" &gt;
  
          &lt;EditText
              android:id="@+id/saveRoute_typeTxt"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:layout_marginTop="17dip"
              android:ems="10"
              android:layout_marginLeft="30dp"
              android:hint="@string/saveRoute_type"
              android:textColor="@color/white"
              android:background="#4e4751"     &gt;
  
              &lt;requestFocus /&gt;
          &lt;/EditText&gt;
  
          &lt;ImageButton
              android:id="@+id/saveRoute_activityType"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"          
              android:src="@drawable/track_walk" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;Button
          android:id="@+id/saveRoute_saveBtn"
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:layout_marginTop="30dp"
          android:background="@color/white"
          android:text="@string/saveRoute_savebutton" /&gt;
  
      &lt;Button
          android:id="@+id/saveRoute_cancelBtn"
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:layout_marginTop="30dp"
          android:background="@color/white"
          android:text="@string/saveRoute_cancel" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>