0
votes

How to pull to refresh?

In Titanium appcelerator I need to show a list of content in tableview. If I pull the view it needs to update. In iPhone I complete but in Android it won't work. Please any one help to solve this problem in Android.

My Android code:-

tableView.addEventListener('scroll',function(e)
{
   var offset = e.contentOffset.y;
   if (offset < -65.0 && !pulling && !reloading)
   {
       var t = Ti.UI.create2DMatrix();
       t = t.rotate(-180);
       pulling = true;
       arrow.animate({transform:t,duration:180});
       statusLabel.text = "Release to refresh...";
   }
   else if((offset > -65.0 && offset < 0 ) && pulling && !reloading)
   {
       pulling = false;
       var t = Ti.UI.create2DMatrix();
       arrow.animate({transform:t,duration:180});
       statusLabel.text = "Pull down to refresh...";
   }    
});

tableView.addEventListener('dragEnd', function(e)
{

   if(pulling && !reloading)
   {
       reloading = true;
       pulling = false;
       arrow.hide();
       actInd.show();
       statusLabel.text = "Reloading...";
       tableView.setContentInsets({top:60},{animated:true});
       tableView.scrollToTop(-60,true);
       arrow.transform=Ti.UI.create2DMatrix();
       beginReloading();
   }
});
2
Hey have figured this out ?? - Antwan

2 Answers

1
votes

Titanium now supports pull to refresh for BOTH Android (> v6.2.0) and iOS (>3.2.0) with a Titanium.UI.TableView, Titanium.UI.ListView or Titanium.UI.ScrollView object.

See the docs:

Sample code taken from the docs:

var win = Ti.UI.createWindow({
    fullscreen:true
});
var counter = 0;

function genData() {
    var data = [];
    for (var i=1; i<=3; i++) {
        data.push({properties:{title:'ROW '+(counter+i)}})
    }
    counter += 3;
    return data;
}

var section = Ti.UI.createListSection();
section.setItems(genData());

var control = Ti.UI.createRefreshControl({
    tintColor:'red'
})

var listView = Ti.UI.createListView({
    sections:[section],
    refreshControl:control
});

control.addEventListener('refreshstart',function(e){
    Ti.API.info('refreshstart');
    setTimeout(function(){
        Ti.API.debug('Timeout');
        section.appendItems(genData());
        control.endRefreshing();
    }, 2000);
})

win.add(listView);
win.open();
0
votes

Is this just the IOS code form the Kitchen Sink example?

There are a couple of attempts at getting this working on Android, though I haven't confirmed that any of them work as expected. From what I understand, the problem is that you can't get the offset the same way in Android as in IOS.

A quick Google search turned up this link, which was referenced from the official Appcelerator forums. https://gist.github.com/903895