title: Multiple Popup Menus
body: <p>I want to use popup menu for two(2) buttons. The way I am achieving it right now is by making two separate xml files popup_menu1.xml and popup_menu2.xml which are inflated for each button, button1 and button2 respectively.
  Popup-menu-1 has two(2) menu items and popup-menu-2 has four(4) menu items.
  The pics are added for more clarification.</p>
  
  <p>popup_menu1.xml has two menu-items, a seperate xml-file
  popup_menu2.xml has four menu-items, a separate xml-file</p>
  
  <p>each file is inflated for individual buttons.</p>
  
  <p><strong>My Question is:</strong> Can I use(inflate) only one(1) xml-file, instead of two separate xml-files, for two(2) buttons and showing two(2) different popup_menus?</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thank you,</p>
  
  <p>P.S: I wanted to add pictures for more clarity, but as a new member they are not allowing me to do it.</p>
  
  <p>Code Added:
  popup_menu1: File1</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/menu001"&gt;
    &lt;group android:id="@+id/group_popupmenu"&gt;
        &lt;item android:id="@+id/menu1"
            android:title="Today's Date"/&gt;
        &lt;item android:id="@+id/menu2"
            android:title="Custom Date"/&gt;
    &lt;/group&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>popup_menu2: File2</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/menu002"&gt;
    &lt;group android:id="@+id/group_popupmenu"&gt;
        &lt;item android:id="@+id/menu1"
            android:title="Last Seven (07) Days"/&gt;
        &lt;item android:id="@+id/menu2"
            android:title="Today"/&gt;
        &lt;item android:id="@+id/menu003"
            android:title="Yesterday"/&gt;
        &lt;item android:id="@+id/menu4"
            android:title="Last Twenty Eight (28) Days"/&gt;
    &lt;/group&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>Edit version 1:
  Code In Activity Class:</p>
  
  <pre><code>// add a click listener to the first button
  startDateButton.setOnClickListener(new View.OnClickListener() {
  public void onClick(View view) {
      PopupMenu popup = new PopupMenu (CampaignDetailsActivity.this, view);
      popup.getMenuInflater().inflate(R.layout.popup_menu_01, popup.getMenu());
      popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
      public boolean onMenuItemClick(MenuItem item) {
  
          switch(item.getItemId()){
      case R.id.menu1:
      // some code here
      case R.id.menu2:
      // some code here   
          }
      return true;
      });
   popup.show();
   }
  });
  
  // add a click listener to the end date button
  endDateButton.setOnClickListener(new View.OnClickListener() {
      public void onClick(View button) {
      PopupMenu popup = new PopupMenu (TestAdlikelyButtonsAndMenuActivity.this, button);
              popup.getMenuInflater().inflate(R.layout.popup_menu2, popup.getMenu());
  
              popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                  public boolean onMenuItemClick(MenuItem item) {
                      switch(item.getItemId()){
                      case R.id.menu1:
                      // some code here
                      case R.id.menu2:
                      // some code here
                      case R.id.menu003:
                      // some code here
                      case R.id.menu4:
                      // some code here
                      }
                      return true;
                  }
              });
          popup.show();
      }
  });
  </code></pre>
  
  <p>Images:</p>
  
  <p><img src="https://i.stack.imgur.com/3bTdw.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/jBZXJ.jpg" alt="enter image description here"></p>