Switch propretychange not working


#1

page-settings.xml

<Page loaded="page_settings_loaded" id="settings_page">
<ActionBar class="action-bar" title="Settings"></ActionBar>
<StackLayout orientation="vertical" id="stack_settings">
<Switch id="switch1" propertyChange="switch_test"/>
  </StackLayout>
</Page>

page-settings.js

var framemodule = require("ui/frame");
var page, switch1;
exports.page_settings_loaded = function (args) {
    page = args.object;
    switch1 = page.getViewById('switch1');
}
exports.switch_test = function () {
    console.log("switch changed");
}

why this isnt working i did exactly same like on documentation


#2

Starting {N} 3.x propertyChange will not working with XML. You have to use direct property listener, here it will be checkedChange

But still that too doesn’t seem working (looks like a issue, have to still debug further) but as a work around you can add a listener programatically.

switch1.on("checkedChange", exports.switch_test);

Update: More info about property change events can be found here


#3

thanks for your answer it’s working