Skip to content

Instantly share code, notes, and snippets.

@jasonkneen
Last active March 15, 2017 18:51
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jasonkneen/b7c6f0cb61988d333092 to your computer and use it in GitHub Desktop.
Save jasonkneen/b7c6f0cb61988d333092 to your computer and use it in GitHub Desktop.
Demo of how to use David Bankier's "Real Switch" for Android here. https://github.com/dbankier/RealSwitch. Add the Module to your TiApp.xml file, add a switch to your Alloy file as normal, but add the module attribute. Drop the ui.js file into your /lib/ folder (you can add to this) and then run the project. On iOS you'll get a regular iOS switc…
$.mySwitch.addEventListener('change',function(e){
Ti.API.info('Switch value: ' + $.mySwitch.value);
});
<Alloy>
<Window>
<Switch id="mySwitch" module="ui"/>
</Window>
</Alloy>
exports.createSwitch = function(args) {
if (OS_ANDROID) {
var RealSwitch = require("com.yydigital.realswitch");
return RealSwitch.createRealSwitch(args);
} else {
return Ti.UI.createSwitch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment