Picker Select and Click events

You must Login before you can answer or comment on any questions.

Hi, I need to make a picker as a navigation menu. When it selects an item, it should fire an event. In my case i want to change the top image. And when we click the selected picker value, it should do another event. That means i want to go to a sub menu. If we cant do this from this picker, Is there any other way to do this?

There is a practical example in the following app.

Click - DiorApp

I don't know whether is done in Titanium or not, but that's what the clients after!

Many Thanks

1 Answer

Accepted Answer

hi,

You can get change event on picker , so you can do work on change event: here is an example for you :

var picker = Ti.UI.createPicker();
 
var data = [];
data[0]=Ti.UI.createPickerRow({title:'1'});
data[1]=Ti.UI.createPickerRow({title:'2',custom_item:'s'});
data[2]=Ti.UI.createPickerRow({title:'3',custom_item:'m'});
data[3]=Ti.UI.createPickerRow({title:'4',custom_item:'g'});
 
// turn on the selection indicator (off by default)
picker.selectionIndicator = true;
 
picker.add(data);
 
win.add(picker);
 
picker.addEventListener('change', function(e) {
    var val = e.row.title;
 
    switch(val) {
        case "1":
            label.text = "Hi I am One";
            break;
        case "2":
            label.text = "Hi I am Two";
            break;
        case "3":
            label.text = "Hi I am Three";
            break;
        case "4":
            label.text = "Hi I am Four";
            break;
    }
});
If you want to know the selected value on the button or any other component click :

You can do a picker.getSelectedRow(0). the params that you pass to getSelectedRow is the column number in a case you havent assign any column just pass 0.

Hope this helps you.

— answered 9 months ago by Moiz Chhatriwala
answer permalink
4 Comments
  • Thank you for your answer. Also is it possible to change the picker design with some custom graphics? I saw there is an example in the Kitcehen sink for values, but i need to change the picker base image and the picker itself. If we cant do it is it possible to use a table view or a web view for this? Many thanks.

    — commented 9 months ago by Gayan Wijenayake

  • We can not change the background image of picker , What you can do is make a view and place a tableview on it, You can set background image of table , and can do this. You can also set header view of table using headerView property of tableview , and can work on click event of tableview.

    — commented 9 months ago by Moiz Chhatriwala

  • Thank you!

    — commented 9 months ago by Gayan Wijenayake

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!