Skip to content

Instantly share code, notes, and snippets.

@MotiurRahman
Created May 22, 2019 18:07
Show Gist options
  • Save MotiurRahman/aaabc3a7c5c8166d9871ca7ce90f2cb6 to your computer and use it in GitHub Desktop.
Save MotiurRahman/aaabc3a7c5c8166d9871ca7ce90f2cb6 to your computer and use it in GitHub Desktop.
TableView with custom row sample code.
var win = Ti.UI.createWindow({
backgroundColor : '#fff',
layout : 'vertical'
});
// Create a TextField.
var textValue = Ti.UI.createTextField({
height : Titanium.UI.SIZE,
top : 10,
color : '#000',
backgroundColor : "gray",
width : Titanium.UI.FILL,
hintText : 'Write somethig then press enter',
softKeyboardOnFocus : Ti.UI.Android.SOFT_KEYBOARD_DEFAULT_ON_FOCUS, // Android only
keyboardType : Ti.UI.KEYBOARD_DEFAULT,
returnKeyType : Ti.UI.RETURNKEY_DEFAULT,
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED
});
// create TableView
var tableData = [];
var tableView = Ti.UI.createTableView({
data : tableData,
top : 10,
});
//var i = 0;
function refresh(data) {
var row = Ti.UI.createTableViewRow({
//className : 'forumEvent', // used to improve table performance
//selectedBackgroundColor : 'white',
//index : i, // custom property, useful for determining the row during events
height : 70,
namevalue : textValue.value,
});
var name = Ti.UI.createLabel({
color : 'red',
id : "name",
font : {
fontFamily : 'Arial',
fontSize : 20,
fontWeight : 'normal'
},
text : textValue.value,
left : 5,
});
name.addEventListener('click', function(e) {
textValue.setValue(e.source.text);
});
row.add(name);
var del = Ti.UI.createButton({
title : 'delete',
right : 10,
height : Ti.UI.SIZE,
width : Ti.UI.SIZE,
id : "delrow",
myrow : row
});
row.add(del);
del.addEventListener('click', function(e) {
tableView.deleteRow(e.source.myrow);
tableData.pop(e.source.namevalue);
});
tableData.push(row);
tableView.setData(tableData);
}
// Listen for return events.
textValue.addEventListener('click', function(e) {
refresh();
//textValue.blur();
//textValue.setValue('');
});
win.add(textValue);
win.add(tableView);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment