0

I just want to show a simple popup menu containing menu items in vertical ordering. Just like Titanium's option dialog. But without radio buttons. I have used androidView as follows, but how can I dismiss this dialog when an option is clicked?

menuBtn.addEventListener("click", function(e) {

var data = [];


for (var n = 0; n < indexToNameAndHandlerMap.length; n++) {

    var row = Ti.UI.createTableViewRow({
        backgroundSelectedColor : '#ffffff',
        backgroundColor : '#ffffff',
        opacity : 1.0,
        height : Ti.UI.SIZE,
        className : 'row',
        objName : 'row',
        layout : "horizontal"
    });

    var movieNameLabel = Ti.UI.createLabel({
        text : indexToNameAndHandlerMap[n].menuItem,
        color : '#000000',
        backgroundColor : '#ffffff',
        textAlign : Titanium.UI.TEXT_ALIGNMENT_LEFT,
        font : {
            fontSize : '20dp',
        },
        width : '96%',
        height: '45dp',
        left: '2%',
        objName : 'movieNameLabel',
        touchEnabled : false
    });

    row.add(movieNameLabel);

    data.push(row);
}

var table = Ti.UI.createTableView(
{
    top : '0%',
    left: 0,
    separatorColor : "#000000",
    backgroundColor : '#ffffff',
});

table.setData(data);

var loginView =Ti.UI.createView({
        backgroundColor : '#ffffff',
    });

    loginView.add(table);


Ti.UI.createOptionDialog({
title:'Select An Option',
androidView:loginView
}).show();


}); 
Aqeel Ashiq
  • 1,988
  • 5
  • 24
  • 57

2 Answers2

3

Try the following code

var loginView =Ti.UI.createView({
    backgroundColor : '#ffffff',
});

loginView.add(table);

var option = Ti.UI.createOptionDialog({
    title:'Select An Option',
    androidView:loginView
});

option.show();

option.addEventListener('click', function(e){
   option.hide(); /*can also use e.source.hide();*/
});
Anand
  • 5,323
  • 5
  • 44
  • 58
  • What for is androidView option used ? – Artur79 Apr 18 '14 at 13:27
  • 1
    Android view option helps to customize your alert dialog. Whatever inside the view will be displayed in the alert dialog. In my answer, the login view will be displayed inside the alert dialog. Check the documentation at http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.AlertDialog-property-androidView – Anand Apr 21 '14 at 04:17
2

you need to add an eventListener to listen for the click event in the dialog to close the window.

http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.OptionDialog-event-click

Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80