title: How to access or create reference to widgets in a DialogFragment
body: <p>I have created a class taht extends from <code>DialogFragment</code>. I went with the custom layout and I added some buttons to this dialog.</p>
  
  <p>I defined fields to the buttons but when I launch the dialog from the main activity I get nullreferenceexception.</p>
  
  <p>Here is the dialog class:</p>
  
  <p>public class PickRewardDialog extends DialogFragment{</p>
  
  <pre><code>private Button mButtonAddCoin;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      mButtonAddCoin = (Button) getDialog().findViewById(R.id.button_dialog_reward_get_coin);
      mButtonAddCoin.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Toast.makeText(getDialog().getContext().getApplicationContext(), "You will" +
                      " receive 5 coins!", Toast.LENGTH_SHORT).show();
          }
      });
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      if(getDialog() != null){
          getDialog().setCanceledOnTouchOutside(false);
      }
      return super.onCreateView(inflater, container, savedInstanceState);
  }
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
  
      Resources res = getActivity().getResources();
      Bundle bundle = getArguments();
  
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      LayoutInflater inflater = getActivity().getLayoutInflater();
      builder.setView(inflater.inflate(R.layout.dialog_pick_reward, null))
      //Positive button
      .setPositiveButton(R.string.dialog_choose_reward_positive_button,
              new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int id) {
                      //do nothing or Dismiss()
                  }
              }
      );
  
      return builder.create();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and the layout:</p>
  
  <p></p>
  
  <pre><code>&lt;ImageView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#FFFFBB33"
      android:contentDescription="@string/app_name"
      android:scaleType="center"
      android:src="@drawable/dialog_title_pick_your_reward"/&gt;
  
  &lt;Button
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Add 5 coins to your account!"
      android:id="@+id/button_dialog_reward_get_coin"
      android:layout_gravity="center_horizontal"/&gt;
  
  &lt;Button
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Get a temorary boost on leaderboard!"
      android:id="@+id/button_doalog_reward_boost"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>So the question is how can I set the clicklistener and do stuff with it?</p>