0

I trying to attach an event listener to a custom button in my action bar, but the click event triggers no action. Can someone please help me to debug.

R.menu.address_menu

<item
    android:id="@+id/address_menu_add"
    android:showAsAction="always"
    android:title="@string/add"
    android:actionLayout="@layout/add"/>
<item
    android:id="@+id/address_menu_setting"
    android:showAsAction="collapseActionView"
    android:title="@string/settings"/>
<item
    android:id="@+id/address_menu_help"
    android:showAsAction="collapseActionView"
    android:title="@string/help"/>
<item
    android:id="@+id/address_menu_privacy"
    android:showAsAction="collapseActionView"
    android:title="@string/privacy_policy"/>

actionview for the button

<Button
    android:id="@+id/add_new_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/btn_basket_full"
    android:layout_gravity="center|center_vertical"
    android:gravity="center|center_vertical"
    android:text="Add"
    android:textColor="#580606"
    android:textAppearance="?android:attr/textAppearanceMedium" />

Event listener added

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.address_menu, menu);

    MenuItem item = menu.findItem(R.id.address_menu_add);
    item.getActionView().setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            addReview();
        }
    });
    return true;
}
4

0 回答 0