var win = Titanium.UI.currentWindow; //app.jsからの値の取得 //alert(Titanium.UI.currentWindow.oneMoreThing); //app.jsへ値を渡す /* Titanium.App.fireEvent('custom',{ message:'イベントメッセージ', profile:{ name:'ネストしたデータも引き渡せます', memo1:'しかしfunctionなどは渡せません', memo2:'そのため子windowのコントロールを外部から操作できません' } }) */ Titanium.App.Properties.setString('message','プロパティのメッセージ'); Titanium.App.fireEvent('custom',{}); //TableViewの追加 var tableView = Titanium.UI.createTableView(); win.add(tableView); //@appceleratorのtweetを取得 var url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=appcelerator'; var refreshTL = function refreshTimeline(){ alert("読み込むよ!"); if(Titanium.Network.online != false){ //HTTPlientオブジェクト生成 var xhr = Titanium.Network.createHTTPClient(); xhr.open('GET',url,false); //レスポンスを受け取るイベント(非同期に実行させる) xhr.onload = function(){ //受け取ったJSONデータをパース var json = JSON.parse(xhr.responseText); for(var i=0; i<json.length; i++){ var row = Titanium.UI.createTableViewRow(); row.height = 180; row.add(Titanium.UI.createLabel({ text:json[i].user.screen_name, top:8, left:64, height:16 })); row.add(Titanium.UI.createLabel({ text:json[i].text, top:32, left:64, width:256, height:'auto' })); row.add(Titanium.UI.createImageView({ image:json[i].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(); }else{ //error alert('offline'); } } refreshTL(); //ウィンドウの右上のボタンを設定 var rightButton = Titanium.UI.createButton({ //title:'再読込' systemButton:Titanium.UI.iPhone.SystemButton.REFRESH }); win.rightNavButton = rightButton; rightButton.addEventListener('click',function(){ //alert('onbt'); refreshTL(); });
コメントをかく