0

Quick Titanium Alloy Question:

I was wondering how can I access the picker element inside the actionview of the android Menu in my controller? The classic $.(idofelement) doesn't seem to work. (and I have no idea why)

<Alloy>
<Window id="window" backgroundColor="#F5F5F5" title="CollegeWorld">
<ActionBar id="actionbar" logo="/icon.png" title="CollegeWorld" />
<Menu id="menu"> <MenuItem id="boardPicker" showAsAction="Ti.Android.SHOW_AS_ACTION_IF_ROOM">

<ActionView>
    <Picker id="picker" opacity="1" selectedRow='2' onChange="changeBoard" zIndex="99999" top="0" right="0" visible="true">
        <PickerColumn id="board">
            <PickerRow title="CIE"/>
            <PickerRow title="Edexcel"/>
        </PickerColumn>

       </Picker>
    </ActionView>

</MenuItem>
</Menu>
</Window>
</Alloy>
Ramy
  • 1
  • 1

1 Answers1

1

To update MenuItem's properties(title, icon...), you can re-create Menu.

Here's how:

var activity = $.window.getActivity();
// Re-create Menu
if(activity){
  activity.onCreateOptionsMenu = function(e){
    var menuItem = e.menu.add({
      title : "New Title",
      visible: true,
      showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS
    });
    menuItem.addEventListener('click', alert);
  };
  activity.invalidateOptionsMenu();// This kicks onCreateOptionsMenu
}

You can access Window's activity only when it's opened.

toshiro
  • 11
  • 2