Hi everyone,
With this code below, I have three events on each row: btnPlus click event, labelSection swipe event and btnDel click event. When I swipe in a row text, btnDel apears, but the click event on this button d oesn't fires. Swipe event and btnPlus event fires perfect.
Does anybody can help on how the red button doesn't fires ?
I am using Mac with OSX 10.9.2
Titanium 3.2.2
Testing on Samsung GT-I8530
This is my code:
var win = Ti.UI.createWindow({ //
backgroundColor: 'black'
});
var tableView = Ti.UI.createTableView({
backgroundColor:'#f2edb2',
editable: true,
allowSelect: true,
top:55
});
var tableData = [];
var OSNAME = Ti.Platform.osname;
var WIDTH = Ti.Platform.displayCaps.platformWidth;
var HEIGHT = Ti.Platform.displayCaps.platformHeight;
var view2 = Ti.UI.createView({ // View dos dados
backgroundColor: '#f2edb2',
textColor: 'white',
height:HEIGHT - 45,
width: WIDTH,
borderRadius: 5,
top: 45
});
win.add(view2);
win.open();
var myTextField = Ti.UI.createTextField({
bordetStyle: Ti.UI.INPUT_BORDERSTYLE_ROUBDED,
windowSoftInputMode: Ti.UI.SOFT_INPUT_ADJUST_PAN,
top: 1,
left: 20,
width: 250,
height: 28
});
tableReadS = [];
for (i = 0; i < 10; i++)
{
tableReadS[i] = 'Test Button tableview row: ' + i;
}
//********************************* ***********************************
function refreshTable()
{
tableView.data = [];
var totalRows = tableReadS.length;
var section = Ti.UI.createTableViewSection({
objName: 'row',
className: 'row',
touchEnabled: true,
editable: true
});
for (var i = 0; i < totalRows; i++)
{
var row = Titanium.UI.createTableViewRow({
className: 'row',
objName: 'row',
touchEnable: false,
editable: true,
hascChild: false,
height:35,
name: 'row'
});
row.addEventListener('click', function(e){
var a=a;
});
//****************************************************************************
var btnPlus = Ti.UI.createButton({
animated: true,
backgroundImage: 'btnPlus.png',
height: 25,
width: 25,
left: 7,
top: 2
});
btnPlus.addEventListener('click', function(e){ //HERE FIRES ON CLICK
var y = y; // do whatever
}) ;
//*****************************************************************************
var labelSection = Titanium.UI.createLabel({
color : 'black',
font : {fontSize : 17,fontWeight: 'normal'},
height : 30,
width: 280,
left: 35,
labId: i,
text: tableReadS[i] //
});
//*****************************************************************************
var btnDel = Ti.UI.createButton({
backgroundImage: 'None',
backgroundColor: 'red',
animated: true,
enabled: true,
font : {fontSize : 12,fontWeight: 'normal',fontColor: 'black'},
height: 30,
width: 50,
title: 'Delete',
visible: false,
touchEnabled: true,
name: 'btnDel',
right : 2,
top: 2
});
btnDel.addEventListener('click', function(e){
var a = a; //NOT FIRE
}) ;
btnDel.addEventListener('swipe', function(e){
var a = a; //NOT FIRE
});
btnDel.addEventListener('delete', function(e){
var a = a; //NOT FIRE
});
btnDel.addEventListener('longpress', function(e){
var a = a; //NOT FIRE
});
btnDel.addEventListener('swipe', function(e){
var a = a; //NOT FIRE
});
//**********************************************************
// For Android Devicces on swipe show button
labelSection.addEventListener('swipe', function(e)
{
if(OSNAME === 'android')
{
clearDel();
for ( i = 0; i < totalRows; i++)
{
if (tableReadS[i] == e.source.text) break;
}
try{
if(tableView.data[0].rows[i].children[0].visible === false)
{
tableView.data[0].rows[i].children[0].visible = true;
}
else
{
tableView.data[0].rows[i].children[0].visible = false;
}
}
catch(e)
{
alert(e.message);
}
}
});
labelSection.addEventListener('click', function(e)
{
clearDel();
});
if(OSNAME == 'android')
{
row.add(btnDel);
}
row.add(btnPlus);
row.add(labelSection);
section.add(row);
} // ************** end for
//*****************************************************************************
var section1 = Ti.UI.createTableViewSection({
height: 37
});
var rowText = Ti.UI.createTableViewRow({});
var myTextField = Ti.UI.createTextField({
returnKeyType: Ti.UI.RETURNKEY_DONE,
backgroundColor: 'white',
hintText: 'Insert a new section',
borderStyle: Ti.UI.INPUT_BORDER_STYLE_BEZEL,
font : {fontSize : 20,fontWeight: 'normal'},
textAligh: 'center',
left: 30,
width: 270,
height: 40,
bottom: 0
});
rowText.add(myTextField);
section1.add(rowText); // Coloca o textField na ultima Row
tableData.push(section, section1);
tableView.setData(tableData);
win.add(tableView);
//*****************************************************************************
}
refreshTable();
// clear delete buttons on android devices
function clearDel()
{
if(OSNAME === 'android')
{
try
{
for (i=0; i < tableReadS.length; i++)
{
if(tableView.data[0].rows[i].children[0].visible)
{
tableView.data[0].rows[i].children[0].visible = false;
}
};
}
catch(e)
{
alert(e.message);
}
}
}
// This is for iOS Delete button
tableView.addEventListener('delete', function(e){
var s = e.section;
Ti.API.info(' title: ' + e.row.name);
Ti.API.info("deleted - row:" + e.row + "index: " + e.index + " section = " + s);
});
↧