title: Custom dialog in fragment
body: <p>I have in my app a class which extends ListFragment. I want to show a simple dialog with the options "Edit" and "Delete" (as Textviews) when long-clicking the list items. Unfortunately, my dialog crashes while instantiating the Textviews.
  Here's my code:
  In MyListFragment class: </p>
  
  <pre><code>@Override
  public void onActivityCreated(Bundle savedState) {
      super.onActivityCreated(savedState);
  
      getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
  
          @Override
          public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1,
                                         int arg2, long arg3) {
  
              showDialog();
              return true;
          }
      });
  }
  
  
  
  protected void showDialog(){
  
      Dialog dialog = new Dialog(getActivity());
      dialog.setCancelable(true);
  
      dialog.setContentView(R.layout.dialog);
  
      TextView edit = (TextView) getView().findViewById(R.id.edit);
      TextView delete = (TextView) getView().findViewById(R.id.delete);
  
  
      edit.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              //Do something
  
          }
      });
      delete.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
               //Do something
  
          }
      });
  
  
  
      dialog.show();
  };
  </code></pre>
  
  <p>The dialog.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="200dp"
      android:layout_height="wrap_content"
      android:id="@+id/dialog"
      android:paddingTop="@dimen/dialog_padding"
      android:paddingBottom="@dimen/dialog_padding"
      &gt;
  
    &lt;TextView
        android:id="@+id/edit"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dialog_row_height"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        android:paddingLeft="6dp"
        android:paddingRight="6dp"
        android:textColor="@color/colorPrimaryText"
        android:textAlignment="center"
        android:textSize="@dimen/text_size"
        android:text="@string/edit" /&gt;
  
    &lt;TextView
        android:id="@+id/delete"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dialog_row_height"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        android:paddingLeft="6dp"
        android:paddingRight="6dp"
        android:textColor="@color/colorPrimaryText"
        android:textAlignment="center"
        android:textSize="@dimen/text_size"
        android:text="@string/delete" /&gt;
  
       &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The logcat says <code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference</code> 
  in fact, I checked via Log.d and the textview results null. 
  I can't figure out why. I'm clearly missing something. 
  Could you please help me understanding the cause of this issue? Thank you a lot!</p>