I just can't get the ActionProvider to show the submenu, and I don't understand why. I have my menu defined in xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/dossier_menu"
android:showAsAction="always"
android:actionProviderClass="com.some.other.mockup.MActionProvider">
</item>
</menu>
action provider class:
public class MActionProvider extends ActionProvider {
private static final String TAG = "MActionProvider";
private static final int LIST_LENGTH = 3;
private Context context;
public MezzActionProvider(Context context) {
super(context);
this.context = context;
}
@Override
public View onCreateActionView() {
View view = View.inflate(context, R.layout.action_layout, null);
return view;
}
@Override
public boolean hasSubMenu() {
Log.d(TAG, "hasSubMenu");
return true;
}
@Override
public boolean onPerformDefaultAction() {
Log.d(TAG, "onPerformDefaultAction");
return super.onPerformDefaultAction();
}
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
Log.d(TAG, "onPrepareSubMenu");
subMenu.clear();
subMenu.add(Menu.NONE, Menu.NONE, 1,"Mezz 1");
subMenu.add(Menu.NONE, Menu.NONE, 2, "Mezz 2");
}
}
and action layout:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mezz State ++"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="4dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="@dimen/buttonHeight"
android:src="@android:drawable/ic_menu_add"
android:layout_alignParentLeft="true"
android:id="@+id/img1"
android:layout_below="@id/textView"/>
I tried to use the button instead of presenting the image, even tried adding a submenu to the menu item in xml, when I click on the action provider, it just does not display the submenu, I canβt understand why.
thanks
source
share