Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1100553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:53:54+00:00 2026-05-17T00:53:54+00:00

I have the following code, which is written for the Titanium framework for mobile

  • 0

I have the following code, which is written for the Titanium framework for mobile application development. The problem that I am having is that the loadPage() method is not calling the other methods. What am I missing here?

Titanium.UI.currentWindow.barColor = Titanium.UI.currentWindow.barColor;
Titanium.UI.currentWindow.title = 'My Media';


function Media()
{

this.properties = {
    currentPage : 1,
    url : 'http://localhost/past?return=json&count=20&page=',
    rowColor: '#fff',
    rowSelectedColor: '#6BBBFA',
    filter: 'filter'
};

this.table = false;
this.wrapper = false;
this.products = false;

/*
    Allow the user to search through all of their media
*/
this.showSearch = function()
{
    var search = Titanium.UI.createSearchBar({
        barColor: Titanium.UI.currentWindow.barColor, 
        showCancel: false
    });

    search.addEventListener('change', function(e)
    {
       e.value; // search string as user types
    });

    search.addEventListener('return', function(e)
    {
       search.blur();
    });

    search.addEventListener('cancel', function(e)
    {
       search.blur();
    });

    return search;
};


/*
    Create a row in the table.  This will actually
    append the row to a pre-existing table
*/
this.createRow = function(product)
{
    var row = Ti.UI.createTableViewRow();

    var image = Ti.UI.createImageView({
        image: product.image,
        top: 5,
        left: 5,
        width:100,
        height:70,
        canScale: true
    });

    var video = Ti.UI.createLabel({
        color: '#000',
        font: {
            fontSize: 14,
            fontWeight: 'bold', 
            fontFamily: 'Arial'
        },
        left: 110,
        top: 2,
        height: 20,
        width: 170,
        clickName: 'video',
        text: product.name
    });

    var date = Ti.UI.createLabel({
        color: '#999',
        font: {
            fontSize: 13,
            fontWeight: 'normal', 
            fontFamily: 'Arial'
        },
        left: 110,
        top: 22,
        height: 20,
        width: 100,
        clickName: 'date',
        text: product.date
    });

    row.height = 80;
    row.className = 'mediaItem';
    row.selectedBackgroundColor = this.properties.rowSelectedColor;
    row.hasDetail = true;
    row.filter = video.text;

    row.add(image);
    row.add(video);
    row.add(date);

    // Add the row to the table
    this.addRowToTable(row);
};


/*
    Add the products to the table view
*/
this.addRows = function()
{
    var item;
    for(item in this.products)
    {
        if(item)
        {
            this.createRow(this.products[item]);
        }
    }

    this.showMoreButton();
};


/*
    If we do not already have a table, let's go ahead and build one now
*/
this.buildTable = function()
{
    if(!this.table)
    {
        // Build out the table
        this.table = Titanium.UI.createTableView({
            search: this.showSearch(),
            filterAttribute: this.properties.filter,
            backgroundColor: '#ffffff'
        });

        this.wrapperView = Titanium.UI.createView({
            backgroundColor: 'transparent'
        });

        this.wrapperView.add(this.table);
        Titanium.UI.currentWindow.add(this.wrapperView);
    }
};


/*
    Append a row to the table (if the table exists)
*/
this.addRowToTable = function(row)
{
    if(this.table)
    {
        this.table.appendRow(row);
    }
};


/*
    Allow the user to choose to show more videos
*/
this.showMoreButton = function()
{
    var row = Ti.UI.createTableViewRow();
    row.backgroundColor = '#6BBBFA';
    row.selectedBackgroundColor = '#666';

    // add custom property to identify this row
    row.isUpdateRow = true;

    var rowText = Ti.UI.createLabel({
        color: '#fff',
        font: {
            fontSize:16, 
            fontWeight:'bold'
        },
        text: 'Show More Videos',
        width: 'auto',
        height: 'auto'
    });
    row.className = 'updated_row';
    row.add(rowText);

    row.addEventListener('click', function(e){
        this.loadPage();
    });

    // Add the row to the table
    this.addRowToTable(row);
};


/*
    We don't want to load the same page 
    multiple times, so increment the page each time
*/
this.incrementPage = function()
{
    this.properties.currentPage = this.properties.currentPage + 1;
};


/*
    Let's go ahead and load a URL and parse it as JSON
    This method will automatically paginate
*/
this.loadPage = function()
{
    xhr = Titanium.Network.createHTTPClient();
    xhr.open('GET', this.properties.url + this.properties.currentPage);

    xhr.onload = function()
    {
        // Set the response
        var response = JSON.parse(xhr.responseText);
        this.products = response.products;

        // Build the table.  This method will only build it if it doesn't yet exist
        this.buildTable();

        // Add rows to the table
        this.addRows();

        // Go ahead and increment the page that we are on
        this.incrementPage();
    };


    xhr.onerror = function(e)
    {
        // If there has been an error, let the user know about it
        var a = Titanium.UI.createAlertDialog({
            title:'Error',
            message: 'There was an error with the request.  Please try again later'
        });

        a.show();
    };

    xhr.send();
};

};

var media = new Media();
media.loadPage();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:53:54+00:00Added an answer on May 17, 2026 at 12:53 am

    you have a scope issue. when you get to this point

    xhr.onload = function() 
    { 
        // Set the response 
        var response = JSON.parse(xhr.responseText); 
        this.products = response.products; 
    
        // Build the table.  This method will only build it if it doesn't yet exist 
        this.buildTable(); 
    
        // Add rows to the table 
        this.addRows(); 
    
        // Go ahead and increment the page that we are on 
        this.incrementPage(); 
    }; 
    

    the name this refers to xhr rather than the Media object. this is commonly addressed by creating a new variable at the top of the Media constructor which points to itself, like

    function Media()     
    {     
         var self = this;
    

    you would then use the self name to refer to the Media object from within xhr.onload.

    xhr.onload = function() 
    { 
        // Set the response 
        var response = JSON.parse(xhr.responseText); 
        self.products = response.products; 
    
        // Build the table.  This method will only build it if it doesn't yet exist 
        self.buildTable(); 
    
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code which stopped working recently. The problem is that no
I have the following code which utilises Guava's Files.readLines() method: List<String> strings = Lists.newArrayList();
I have string which is of format: ;1=2011-10-23T16:16:53+0530;2=2011-10-23T16:16:53+0530;3=2011-10-23T16:16:53+0530;4=2011-10-23T16:16:53+0530; I have written following code to
I have written the following code which will does not work but the second
I have written the following code which works, but im wondering can I make
I have written following code which generates a browse and upload button.i want to
I often have to debug Java code which was written so that there is
I have a php scrip, in which i have written the following code $client
I have following code which works for radio buttons but need to be changed
I want to know is below code correct ? I have following code which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.