'CheckBox in Nativescript (ios and Android)
What is the best way to create checkbox in Nativescript with javascript?
I know if I use checkbox it's only for Android, and I have problems with the switches. So I will like use images to reproduce a checkbox.
I have this XML
<ListView items="{{ whishList }}">
<ListView.itemTemplate>
<GridLayout class="listes" columns="auto,*,30">
<Image id="id_check" src="res://selectoff" tap="CheckList"/>
<Label id="id_wishlist" text="{{ id_wishlist }}"/>
</GridLayout>
</ListView.itemTemplate>
</ListView>
If I tap the image, I would Like to change the image of item. And with JS I need to change the image, but this changes only the last item:
exports.CheckList = function(args){var customControl = args.object;
customControl.bindingContext = whishList;
var checkID = customControl.parent.parent.getViewById("id_check");
checkID.src ="res://selecton";
}
Solution 1:[1]
My solution is the following
var customControl = args.object;
var checkID = customControl.parent.getViewById("id_check");
checkID.src ="res://checkon";
Solution 2:[2]
Solution by OP.
The checkbox plugin described by @Brad Martin github.com/bradmartin/nativescript-checkbox works, the problem is in the itemtap, if this is in a list-view with others components.
For example: If we would like the itemTap for each element, with the checkbox is not possible, the solution is set focusable to false.
exports.CheckLoaded=function(args) {
// This is only an issue in Android
if (app.android) {
var ChBox= args.object;
ChBox.android.setFocusable(false);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Israel |
Solution 2 |