Autore Topic: findItem non funziona nei submenu?  (Letto 466 volte)

Offline zipgenius

  • Utente junior
  • **
  • Post: 80
  • Respect: +17
    • matteoriso
    • Mostra profilo
    • ZipGenius
  • Dispositivo Android:
    Samsung Galaxy S
  • Play Store ID:
    Wininizio.it Software
  • Sistema operativo:
    Windows 7
findItem non funziona nei submenu?
« il: 16 Novembre 2011, 14:46:16 CET »
0
Ciao.
Ho un menù così strutturato:

Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/mnuAdd" android:title="@string/mnu_lmain_add" android:showAsAction="ifRoom|withText|collapseActionView" android:orderInCategory="0" android:titleCondensed="@string/mnu_lmain_add_cond" android:visible="true" android:icon="@drawable/ic_menu_add_white"></item>
    <item android:id="@+id/mnuExtract" android:title="@string/mnu_lmain_extract" android:showAsAction="ifRoom|withText|collapseActionView" android:orderInCategory="1" android:titleCondensed="@string/mnu_lmain_extract_cond" android:visible="true" android:icon="@drawable/ic_menu_extract_white"></item>
    <item android:id="@+id/mnuDelete" android:title="@string/mnu_lmain_delete" android:showAsAction="ifRoom|withText|collapseActionView" android:orderInCategory="2" android:titleCondensed="@string/mnu_lmain_delete_cond" android:icon="@drawable/ic_menu_delete_white"></item>
    <item android:id="@+id/mnuExtr1" android:titleCondensed="@string/mnu_lmain_extract_cond" android:title="@string/mnu_lmain_extract" android:visible="true" android:orderInCategory="3" android:showAsAction="never" android:menuCategory="system">
        <menu>
            <item android:id="@+id/mnuExtrHere" android:titleCondensed="@string/mnu_lmain_extrhere_cond" android:title="@string/mnu_lmain_extrhere" android:showAsAction="never" android:enabled="true" android:visible="true" android:orderInCategory="1" android:menuCategory="system"/>
            <item android:id="@+id/mnuExtrHereIn" android:orderInCategory="2" android:titleCondensed="@string/mnu_lmain_extrherein_cond" android:enabled="true" android:showAsAction="never" android:title="@string/mnu_lmain_extrherein" android:visible="true" android:menuCategory="system"/>
        </menu>
    </item>  

</menu>

Vorrei fare in modo che il Title del menuitem "mnuExtrHereIn" (inserito inun sottomenù) cambi quando l'utente apre il menù e a determinate condizioni.

Ho provato con questo codice:
Codice (Java): [Seleziona]
@Override
        public boolean onPrepareOptionsMenu(Menu menu) {
                MenuItem mnuExtrHereIn = menu.findItem(R.id.mnuExtrHereIn);
                File F = new File(ActiveFilename);
                mnuExtrHereIn.setTitle(String.format(getString(R.string.mnu_lmain_extrherein), F.getName()));
                mnuExtrHereIn.setTitleCondensed(String.format(getString(R.string.mnu_lmain_extrherein_cond), F.getName()));
                return super.onPrepareOptionsMenu(menu);;
        }

ma l'applicazione va in crash proprio quando viene chiamato "setTitle".
Possibile che menu.findItem mi restituisca null anziché l'item desiderato?