var win = Titanium.UI.currentWindow; var searchBar = Titanium.UI.createSearchBar({ showCancel:true, height:43, top:0 }); var tableView = Titanium.UI.createTableView({ top:43 }); win.add(searchBar); win.add(tableView); //@appceleratorのtweetを取得 var url = 'http://search.twitter.com/search.json'; var refreshTimeline = function(){ //alert("読み込むよ!"); if(Titanium.Network.online != false){ //HTTPclientオブジェクト生成 var xhr = Titanium.Network.createHTTPClient(); xhr.open('GET',url,false); //レスポンスを受け取るイベント(非同期に実行させる) xhr.onload = function(){ //表示内容をいったんクリアする tableView.data = []; //受け取ったJSONデータをパース var json = JSON.parse(this.responseText); //JSON構造が違うため、json.lengthではなく、json.results.length for(var i=0; i<json.results.length; i++){ var tweet = json.results[i]; tweet.user = {}; tweet.user.screen_name = tweet.from_user; tweet.user.name = tweet.from_user; tweet.user.profile_image_url = tweet.profile_image_url; //ここからは基本的に同じ var row = Titanium.UI.createTableViewRow(); row.height = 180; row.add(Titanium.UI.createLabel({ //tweet変数を経由して取得する text:tweet.user.screen_name, top:8, left:64, height:16 })); row.add(Titanium.UI.createLabel({ text:tweet.text, top:32, left:64, width:256, height:'auto' })); row.add(Titanium.UI.createImageView({ image:tweet.user.profile_image_url, top:8, left:8, width:48, height:48 })); tableView.appendRow(row); } }; //error xhr.onerror = function(error){ //error message alert(error); }; //send xhr.send({ q:searchBar.value, lang:'ja', locale:'ja' }); }else{ //error alert('offline'); } } refreshTimeline(); //ウィンドウの右上のボタンを設定 var rightButton = Titanium.UI.createButton({ //title:'再読込' systemButton:Titanium.UI.iPhone.SystemButton.REFRESH }); win.rightNavButton = rightButton; rightButton.addEventListener('click',function(){ //alert('onbt'); refreshTimeline(); }); //検索開始とキーボートを閉じるイベントを設定する searchBar.addEventListener('cancel',function(){ searchBar.blur(); }); searchBar.addEventListener('return',function(){ //検索語の保存 Titanium.App.Properties.setString('query_string',searchBar.value); searchBar.blur(); refreshTimeline(); }); //保存された検索語があれば初期表示 if (Titanium.App.Properties.getString('query_string',null)) { searchBar.value = Titanium.App.Properties.getString('query_string'); refreshTimeline(); };
このページへのコメント
ocWgsV I am so grateful for your article post. Will read on...
e1w1Q9 I value the post.Really looking forward to read more. Awesome.
gOsipw <a href="http://oeqtqkxjlrmo.com/">oeqtqkxjlrmo</a>, [url=http://basavzozrvba.com/]basavzozrvba[/url], [link=http://mdamevnntvss.com/]mdamevnntvss[/link], http://ctimepfwvjam.com/
GKRuKv <a href="http://xwfhcbluvhco.com/">xwfhcbluvhco</a>, [url=http://fbwbrbkyhlcw.com/]fbwbrbkyhlcw[/url], [link=http://exqrqqzeichq.com/]exqrqqzeichq[/link], http://pyjbqwslcwpm.com/