Playlist MyTV untuk smart TV berserta intisari rancangan bermula RM4.99 sebulan. Selanjutnya →

Android Popup Menu module for Titanium

Selasa, 16 September 2014, 6:52 am0

Android Popup Menu is a menu that need to be attached to an anchor view.

popup-menu popup-menu-abmenuitem

var win = Ti.UI.createWindow({
    exitOnClose: true,
    title: 'PopupMenu'
});

var popup = require('nc.popup');

var btn = Ti.UI.createButton({
    title: 'Show popup'
});
btn.addEventListener('click', function() {
    var menu = popup.createPopupMenu({
        options: ['Item A', 'Item B', 'Item C'],
        view: btn
    });
    menu.addEventListener('click', function(e) {
        alert('Selected item: '+e.index);
    });
    menu.addEventListener('dismiss', function() {
        alert('popup menu has been dismissed');
    });
    menu.show();
});
win.add(btn);
win.addEventListener('open', function() { var activity = this.activity; if (activity) { activity.onCreateOptionsMenu = function(e) { var addMenu = e.menu.add({ title: 'Add', showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS }); addMenu.addEventListener('click', function() { var menu = popup.createPopupMenu({ options: ['User', 'Project', 'Item'], view: addMenu }); menu.addEventListener('click', function(e) { Ti.API.info('Selected item: '+e.index); }); menu.show(); }); }; } });
win.open();

Download from Github

(my first open source Titanium module <o/)

Tulis komen: