我正在使用钛来开发 Android 应用程序。我正在使用以下代码来显示数据和使用表格视图。当我单击comment_btn 时,表格视图中会附加一个新行。它工作正常。但是当我单击返回按钮或转到另一个窗口并再次返回到同一个窗口时我添加了我的新行,新添加的行不保留。我也尝试 了insertRowAfter但它给了我相同的结果。我使用了以下代码:
for (var i=0;i<5;i++)
{
var row = Ti.UI.createTableViewRow({height:'auto',className:"row"});
var comments = Ti.UI.createLabel(
{
text:'new comment',
height:'auto',
font:{fontSize:12, fontFamily:'Helvetica Neue'},
color:'#000',
width:'auto',
textAlign:'left',
top:10,
left:40,
});row.add(comments);
}
comment_table.setData(data);
commnet.add(comment_table);
var comment_btn = Titanium.UI.createButton(
{
title:'comment',
height:60,
width:60,
bottom:-5,
left:-2,
});
comment.add(comment_btn);
var comment_box = Titanium.UI.createTextArea({
borderRadius:5,
backgroundColor:'#EEE',
editable: true,
height:30,
width:200,
top:10,
font:{fontSize:15,fontFamily:'Marker Felt'},
color:'#000',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderRadius:5,
});
comment.add(comment_box);
comment_btn.addEventListener('click', function()
{
comment_table.appendRow({title:comment_box.value});
//comment_table.insertRowAfter(3,{'title':comment_box.value});
}