【问题标题】:How to implement long press/swipe and delete on table rows - android titanium?如何在表格行上实现长按/滑动和删除 - android Titan?
【发布时间】:2012-08-01 05:56:54
【问题描述】:

我有一个 tableView 有一些带有标签的行。我想在特定行上长按/滑动时删除行。我已经为 tableView 添加了长按事件,但它的回调方法将参数重新设置为 tableViewRow 中的标签。

如何获取所选行的索引???

table.addEventListener('longpress', function(e) {
            alert(e.source); //showing LabelProxy@2389hf

        });

【问题讨论】:

  • 只能在 iOS 中使用 tableview 的可编辑属性,而不能在 Android 中使用。

标签: android mobile view titanium tableview


【解决方案1】:

尝试下面的代码删除 longClick 上的行。

var win = Ti.UI.currentWindow;
var data=[];
for (var x = 0; x < 4; x++) {
//var view = Ti.UI.createView();
var label = Ti.UI.createLabel({
    text : 'Row Label ' + x,
    height : 'auto',
    width : 'auto',
    color : '#336699',
    left : 10
});
var row = Ti.UI.createTableViewRow({
    height : 50
});
row.add(label);
    data.push(row);
}

// create table view
var tableview = Titanium.UI.createTableView({
    data : data
});
tableview.addEventListener('longclick', function(e) {
    tableview.deleteRow(e.index);
});
win.add(tableview);

【讨论】:

  • e.index 不是 tableView 索引,它会返回标签对象.. :(
  • 嗨 Udhaya,您可以将 LabId 之类的自定义变量添加到标签中,当您长按行时,您可以像这样获取该标签的对象alert(JSON.stringify(e.source.LabId));跨度>
  • 您也可以使用 e.row.index 来查找在 tableview 中选择了哪一行。
  • 我刚刚检查了 e.source,如果它的标签使用 e.source.parent.. 已修复,谢谢朋友..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-17
  • 2015-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-25
相关资源
最近更新 更多