Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (lazyload)
Viewing all articles
Browse latest Browse all 4

How to reset a lazy loaded list view when closing a window?

$
0
0

I am not sure what I am missing here. I want to reset the listview when I click the back button so totalLoaded to 0 and only the 1st 40 pages load. When I open the page after it is closes all of the rows that were previous loaded remain.

var row_limit = 0;
var totalLoaded = 0;
function genData() {
     var data = [];
 
     var commons = require('/ui/dbase/dbs');
 
     var db = commons.getDb_abb();
 
     // var db = Ti.Database.open('abb');
 
     var uppd = 0;
     if (totalLoaded < 39) {
          uppd = 40;
     } else {
          uppd = row_limit;
     }
 
 
 
     Ti.API.info('uppd', uppd);
 
     var resultSet = db.execute("SELECT * FROM abbrev limit ?", uppd);
     while (resultSet.isValidRow()) {
          totalLoaded++;
 
          data.push({
               properties : {
                    searchableText : resultSet.fieldByName('name')
               },
               avatar : {
                    text : resultSet.fieldByName('name')
               },
               info : {
                    text : resultSet.fieldByName('width')
               }
          });
 
          resultSet.next();
     }
     resultSet.close();
 
     db.close();
 
     return data;
}
 
function list_performance_contacts(_args) {
     var myFontName = Ti.App.Properties.getString('fnts');
     var myFontSize = Ti.App.Properties.getInt('fntSize');
 
     var $$ = require("ui/handheld/styles");
     var win = Ti.UI.createWindow($$.window1);
 
     if (Ti.Android) {
          win.addEventListener("open", function() {
               var activity = win.getActivity();
               if (activity && activity.actionBar) {
                    activity.actionBar.setDisplayHomeAsUp(true);
                    activity.actionBar.setTitle(_args.z_cat);
                    activity.actionBar.onHomeIconItemSelected = function() {
                         win.close();
                    };
               }
          });
     } else {
          var sw = Ti.UI.createLabel({
               left : 75,
               color : 'white',
               height : Ti.UI.SIZE,
               width : Ti.UI.SIZE,
               font : {
                    fontSize : 20 + myFontSize,
                    fontFamily : myFontName,
                    fontWeight : 'bold'
               },
               text : _args.z_title
          });
          win.titleControl = sw;
          sw.minimumFontSize = 8;
 
          var backbutton = Titanium.UI.createButton({
               backgroundImage : 'images/backA.png',
               width : 20,
               height : 20
          });
          backbutton.addEventListener('click', function() {
               win.close();
        var totalLoaded = 0;
 
          });
          win.leftNavButton = backbutton;
 
          win.extendEdges = Ti.UI.EXTEND_EDGE_ALL;
          win.barImage = '/images/rows13/navBarLine.png';
          win.shadowImage = '/images/rows13/navBarLine.png';
 
          var sv = Ti.UI.createSearchBar({
               barColor : '#14b0f1',
               borderColor : '#14b0f1',
               backgroundImage : '/images/rows13/navBarLine.png',
               borderStyle : Titanium.UI.INPUT_BORDERSTYLE_NONE,
               showCancel : false,
               height : 44,
               top : 0,
               width : Ti.UI.FILL
          });
 
          win.add(sv);
 
     }
 
     var myTemplate = {
          properties : {
               height : Ti.UI.SIZE,
               searchableText : ""
 
          },
          childTemplates : [{
               type : 'Ti.UI.Label',
               bindId : 'avatar',
               properties : {
                    left : 16,
                    height : 20,
                    color : 'black',
                    font : {
                         fontSize : 17,
                         fontWeight : 'bold'
                    },
                    top : 0
               },
          }, {
               type : 'Ti.UI.Label',
               bindId : 'info',
               properties : {
                    left : 16,
                    bottom : 0,
                    top : 20,
                    height : Ti.UI.SIZE,
                    color : '#8e8e93',
 
                    font : {
                         fontSize : 12,
                         fontStyle : 'italic'
                    }
               },
          }]
     };
 
     var section = Ti.UI.createListSection({
          headerTitle : ''
     });
     section.setItems(genData());
 
     var listView = Ti.UI.createListView({
          top : 44,
          sections : [section],
          templates : {
               'template' : myTemplate
          },
          defaultItemTemplate : 'template',
          backgroundColor : 'white'
     });
 
     listView.setMarker({
          sectionIndex : 0,
          itemIndex : (listView.sections[0].items.length - 10)
     });
 
     listView.addEventListener("marker", function(e) {
          row_limit += 40;
          Ti.API.info('row_limit', totalLoaded);
 
          var animationStyle = !listView.sections[0].items.length ? Ti.UI.iPhone.RowAnimationStyle.NONE : null;
          listView.sections[0].appendItems(genData(), animationStyle);
          listView.setMarker({
               sectionIndex : 0,
               itemIndex : (listView.sections[0].items.length - 10)
          });
 
     });
 
     sv.addEventListener('change', function(e) {
          listView.searchText = e.value;
     });
 
     win.add(listView);
 
     return win;
}
 
module.exports = list_performance_contacts;

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images