1
希望這是我今天最後一個問題......哦哦的Android鈦覆蓋(清表)
這樣的IM填充了從用戶輸入表:
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();
});
問題是我的第二搜索覆蓋我的第一次搜索witouth刪除表,所以它顯示兩個表在彼此之上...你可以看到我試圖刪除與typeoff = undefined的前一張表,但這不起作用...任何想法如何我可以刪除以前填滿的表格嗎?我試圖做一個刪除,但這顯然會引發錯誤,因爲表格不存在在第一...
不要在onload()中創建一個表,在函數中定義一個表並嘗試用於添加行的setData()方法。 – 2011-12-29 10:03:31