title: Popup Menu in custom ListView
body: <p>What I want to achieve:</p>
  
  <p>I have a custom ListView adapter. To each Listitem I want to add a popup menu, pretty similar to the ListView in the current Google Play application.</p>
  
  <p><img src="https://i.stack.imgur.com/asFdW.png" alt="Screenshot of Google Play items"></p>
  
  <p>This is what I tried:
  Most of my code comes from this Android sample <em>samples\android-19\ui\ActionBarCompat-ListPopupMenu</em></p>
  
  <p><strong>CustomFragmentPageAdapter.java</strong>:</p>
  
  <pre><code>// create new fragment
  mCustomFragment = CustomFragment.newInstance(position);
  </code></pre>
  
  <p><strong>CustomFragment.java</strong></p>
  
  <pre><code>public class CustomFragment extends ListFragment implements View.OnClickListener{
  
  ...
  
  @Override
  public void onClick(final View v) {
      v.post(new Runnable() {
          @Override
          public void run() {
              showPopupMenu(v);
          }
      });
  }
  
  private void showPopupMenu(View view) {
  
      PopupMenu popup = new PopupMenu(getActivity(), view);
  
      popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
  
      popup.show();
  }
  </code></pre>
  
  <p><strong>CustomArrayAdapter</strong>:</p>
  
  <pre><code>public class CustomAdapter extends ArrayAdapter&lt;WatchListPlayerItem&gt; {
      ...    
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          final int pos = position;
  
          LayoutInflater inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          final View rowView = inflater.inflate(R.layout.watch_list_row, parent, false);
  
          View popupButton = rowView.findViewById(R.id.imgPopUp);
  
          popupButton.setTag(getItem(position));
  
          popupButton.setOnClickListener(mFragment);
  
          return rowView;
      }
  }
  </code></pre>
  
  <p><strong>popup_menu.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item
          android:id="@+id/install"
          android:title="Install" /&gt;
      &lt;item
          android:id="@+id/addtowishlist"
          android:title="Add to wishlist" /&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p><strong>Logcat output</strong>:</p>
  
  <pre><code>java.lang.RuntimeException: Failed to resolve attribute at index 6
              at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:603)
              at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6423)
              at android.view.ViewGroup$MarginLayoutParams.&lt;init&gt;(ViewGroup.java:6591)
              at android.widget.FrameLayout$LayoutParams.&lt;init&gt;(FrameLayout.java:735)
  ...
  </code></pre>
  
  <p>The error is thrown at popup.show() in my CustomFragment.</p>
  
  <p>This error is clearly driving me crazy and ANY help to solve this issue is highly appreciated!</p>