What I want to achieve:
I have a custom ListView adapter. For each Listitem, I want to add a popup menu similar to the ListView in the current Google Play application.

This is what I tried: Most of my code comes from these sample Android \ android-19 \ ui \ ActionBarCompat-ListPopupMenu samples
CustomFragmentPageAdapter.java
// create new fragment mCustomFragment = CustomFragment.newInstance(position);
CustomFragment.java
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(); }
CustomArrayAdapter
public class CustomAdapter extends ArrayAdapter<WatchListPlayerItem> { ... @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; } }
popup_menu.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/install" android:title="Install" /> <item android:id="@+id/addtowishlist" android:title="Add to wishlist" /> </menu>
Logcat Output :
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.<init>(ViewGroup.java:6591) at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:735) ...
The error is being called in popup.show () in my CustomFragment.
This mistake is clearly driving me crazy, and ANY help in solving this problem is highly appreciated!
java android android-listview listview runtimeexception android-adapter
Al0x Jan 05 '15 at 15:41 2015-01-05 15:41
source share