title: Why can I use onClick in an activity/feed, but, NOT in a dialog fragment?
body: <p>On Android here is for example an excellent code fragment,</p>
  
  <p>showing how to achieve five buttons on a <strong>dialog fragment</strong>...</p>
  
  <hr>
  
  <p><a href="https://stackoverflow.com/q/19381185/294884">android DialogFragment android:onClick=&quot;buttonCancel&quot; causes IllegalStateException could not find a method</a></p>
  
  <p>in your DialogFragment, you have to <strong>setOnClickListener(this)</strong> for all of your buttons/imageviews etc.</p>
  
  <p>Then you implement View.OnClickListener and have a routine like this...</p>
  
  <pre><code>public void onClick(View v)
      {
      Utils.Log("Fucking 'A' sort of... ");
      switch (v.getId())
          {
          case R.id.postfragment_send:
              break;
          etc etc etc
          default:
              break;
          }
      }
  </code></pre>
  
  <p>That's all fantastic.  BUT.</p>
  
  <hr>
  
  <p>Over in my main activity, where I have a ListView. The custom cells have five buttons.  Very simply, in the main activity, I have five routines named whatever I like...</p>
  
  <pre><code>public void clickedComments(View v)
      {
      int position = feed.getPositionForView(v);
      ...etc etc
      }
  public void clickedExplosions(View v)
      {
      int position = feed.getPositionForView(v);
      ...etc etc
      }
  public void clickedTanks(View v)
      {
      int position = feed.getPositionForView(v);
      ...etc etc
      }
  </code></pre>
  
  <p>Then you just do this which is unbelievably easy ("screw Xcode!") ...</p>
  
  <p><img src="https://i.stack.imgur.com/AEhaQ.png" alt="enter image description here"></p>
  
  <p>Amazing!</p>
  
  <hr>
  
  <p>My question, <strong>why can't I use the 'onClick system' in dialog fragments?</strong></p>
  
  <p>What am I doing wrong? Can an android expert explain what the fundamental difference is between the two?  For the record my projects are 4.1+ only.</p>
  
  <p>Thanks!!</p>
  
  <hr>
  
  <p>Here I am pasting in a full example of a fragment, using the first method described above.</p>
  
  <pre><code>public class HappyPopupFragment extends DialogFragment implements View.OnClickListener
      {
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState)
          {
          Dialog dialog = super.onCreateDialog(savedInstanceState);
  
          dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
          dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
          dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
  
          return dialog;
          }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
          {
          View view = inflater.inflate(R.layout.happy_popup, container);
          _setupButtons(view);
          return view;
          }
  
      public void onClick(View v)
          {
          Utils.Log("Fucking 'A' sort of... ");
          switch (v.getId())
              {
              case R.id.button_a:
                  Utils.Log("tanks !!");
                  break;
  
              case R.id.button_b:
                  Utils.Log("bombs !!");
                  break;
  
              case R.id.button_c:
                  Utils.Log("guns !!");
                  break;
  
              case R.id.button_d:
                  Utils.Log("ammo !!");
                  break;
  
              default:
                  break;
              }
          }
  
      private void _setupButtons(View view)
          {
          ((ImageView)view.findViewById(R.id.button_a)).setOnClickListener(this);
          ((ImageView)view.findViewById(R.id.button_b)).setOnClickListener(this);
          ((ImageView)view.findViewById(R.id.button_c)).setOnClickListener(this);
          ((TextView)view.findViewById(R.id.button_d)).setOnClickListener(this);
          }
  
      }
  </code></pre>