Android titanium overwrite(清表)

标签 android titanium

希望这是我今天的最后一个问题... O.o

所以我用用户的输入填充了一个表:

var textField = Ti.UI.createTextField({
hintText:"Zoeken over twitter",
backgroundColor:"#fff",
borderColor:"#fff",
borderWidth:1,
borderRadius:10,
left:10,
right:10,
top:10,
height:50
});
Ti.UI.currentWindow.add(textField);

var buttonSearch = Ti.UI.createButton({
title:"Zoeken",
left:10,
right:10,
top:70,
height:50
});
Ti.UI.currentWindow.add(buttonSearch);

buttonSearch.addEventListener("click", function() {

    if ( typeof tableview == 'undefined' ) {

    } else {
       Ti.UI.currentWindow.remove(tableview);
    }

var twitterUserName = textField.value;
var httpClient = Ti.Network.createHTTPClient();
httpClient.timeout = 10000;
httpClient.open("GET","http://api.twitter.com/1/statuses/user_timeline.json?count=10&screen_name=" + twitterUserName);


var twitterData = [];
httpClient.onload = function() {
    try {

        var tweets = JSON.parse(this.responseText);
        for (var i=0; i < tweets.length; i++) {


for (var i=0; i < tweets.length; i++) {

            var tweetText = tweets[i].text;
            var user = tweets[i].user.screen_name;
            var avatar = tweets[i].user.profile_image_url;
            var created_at = tweets[i].created_at;

            var row = Ti.UI.createTableViewRow({hasChild:true,
                height:'auto'});

var postView = Ti.UI.createView({
                height:'auto',
                layout:'vertical',
                left:5,
                top:5,
                bottom:5,
                right:5
            });

            var avatarImageView = Ti.UI.createImageView({
                image:avatar,
                left:0,
                top:0,
                height:48,
                width:48
            });

            postView.add(avatarImageView);

            var userLabel = Ti.UI.createLabel({
                text:user,
                left:54,
                width:120,
                top:-48,
                bottom:2,
                height:16,
                textAlign:'left',
                color:'#444444',
                font:{fontFamily:'Trebuchet MS',fontSize:14,
                    fontWeight:'bold'}
            });

            postView.add(userLabel);

            var dateLabel = Ti.UI.createLabel({
                text:created_at,
                right:0,
                top:-18,
                bottom:2,
                height:14,
                textAlign:'right',
                width:110,
                color:'#444444',
                font:{fontFamily:'Trebuchet MS',fontSize:12}
            });

            postView.add(dateLabel);

            var tweetTextLabel = Ti.UI.createLabel({
                text:tweetText,
                left:54,
                top:0,
                bottom:2,
                height:'auto',
                width:236,
                textAlign:'left',
                font:{fontSize:14}
            });

            postView.add(tweetTextLabel);
            row.add(postView);
            twitterData[i] = row;
        }


    }
    var tableview = Titanium.UI.createTableView({data:twitterData,
            minRowHeight:58, top:130});
        Ti.UI.currentWindow.add(tableview);

    } catch(E) {
        alert(E);
    }
};
httpClient.send();  
});

问题是我的第二次搜索覆盖了我的第一次搜索,没有删除表格,所以它显示了 2 个表格在彼此之上......正如你所看到的,我试图删除前一个带有 typeoff = undefined 的表格,但这并没有工作...关于如何删除以前填满的表格的任何想法?我试图只删除一个,但这显然会引发错误,因为该表最初不存在...

最佳答案

我就是这样做的。

if (tableview.data.length > 0) {
    for (var i = tableview.data[0].rows.length-1; i >= 0; i--) {
        tableview.deleteRow(i);
    }
}

关于Android titanium overwrite(清表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8659266/

相关文章:

android - 有什么办法可以在 android 和 i-os 的钛合金应用程序中使用 sqlite 数据库吗?

iphone - 如何判断应用程序是由于 Titanium 中的推送通知而打开还是恢复?

android - 在 AOSP 中构建 framework.jar

android - Facebook apprequests 对话框总是返回已取消的 Titanium Android?

android - wdullaer日期时间选择器库导致支持库不同版本错误

android - 如何通过 Android 上的 Intent 启动 "Navigation for google maps go"

titanium - 在 Titanium 移动应用程序中添加计时器

javascript - 修改合金项目中的小部件

Android:单击搜索时,ActionBar 图标和导航下拉菜单之间的边距会发生变化

Android:模拟长时间运行