Last active
November 8, 2016 12:51
-
-
Save samueleastdev/573eac7e2d3a8179e7dcd4402c4b4479 to your computer and use it in GitHub Desktop.
Appcelerator ListView set a background selected colour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toggleCheck(_event) { | |
var items = _event.section.getItems(); | |
for (var i = 0; i < items.length; i++) { | |
var resetItem = _event.section.getItemAt(i); | |
resetItem.properties.backgroundColor = Alloy.Globals.Device.brandColorBg; | |
_event.section.updateItemAt(i, resetItem); | |
}; | |
var item = _event.section.getItemAt(_event.itemIndex); | |
item.properties.backgroundColor = "#696969"; | |
_event.section.updateItemAt(_event.itemIndex, item); | |
results[($.quizContainer.getCurrentPage())] = item.answer.val; | |
} | |
var myTemplate = { | |
events: { | |
click: toggleCheck | |
}, | |
childTemplates: [{ // Title | |
type: 'Ti.UI.View', // Use a label for the title | |
properties: { // Sets the label properties | |
touchEnabled: false, | |
top: 0, | |
left: 0, | |
width: Ti.UI.FILL, | |
height: (OS_ANDROID) ? 40 : Ti.UI.FILL | |
} | |
}, { // Title | |
type: 'Ti.UI.Label', // Use a label for the title | |
bindId: 'answer', // Maps to a custom info property of the item data | |
properties: { // Sets the label properties | |
touchEnabled: false, | |
left: 10, | |
width: Ti.UI.FILL, | |
textAlign: Titanium.UI.TEXT_ALIGNMENT_LEFT, | |
color: Alloy.Globals.Device.brandColorText, | |
font: { | |
fontSize: 16, | |
fontFamily: Alloy.Globals.Device.textFontMedium | |
} | |
} | |
}] | |
}; | |
var listView = Ti.UI.createListView({ | |
templates: { | |
'template': myTemplate | |
}, | |
defaultItemTemplate: 'template', | |
separatorColor: '#fff', | |
separatorStyle: Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_SINGLE_LINE, | |
top: 10, | |
left: 20, | |
right: 20 | |
}); | |
if (OS_IOS) { | |
listView.setRowSeparatorInsets({ | |
left: 0, | |
right: 0 | |
}); | |
} | |
var sections = []; | |
var answerSection = Ti.UI.createListSection(); | |
var answersDataSet = []; | |
for (var a = 0; a < data[i].answers.length; a++) { | |
answersDataSet.push({ | |
properties: { | |
backgroundColor: Alloy.Globals.Device.brandColorBg, | |
accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_NONE, | |
}, | |
answer: { | |
text: data[i].answers[a].title, | |
val: data[i].answers[a].val | |
} | |
}); | |
} | |
answerSection.setItems(answersDataSet); | |
sections.push(answerSection); | |
listView.setSections(sections); | |
card.add(listView); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment