изменение пункта меню программно не работает в Android
У меня есть пункт меню, и я хочу программно изменить его видимость. Меню это
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/pencil"
android:orderInCategory="100"
android:showAsAction="always"
android:visible="true"
android:title="@string/for_pencil"/>
</menu>
то где-то в моем коде
((MenuItem) findViewById(R.id. pencil)).setVisible(false);
Ошибка:
E/AndroidRuntime(13845): FATAL EXCEPTION: main
E/AndroidRuntime(13845): java.lang.ClassCastException: com.android.internal.view.menu.ActionMenuItemView cannot be cast to android.view.MenuItem
Любая помощь разобраться с этим?