display current user photo in image view

You must Login before you can answer or comment on any questions.

Hi all. I wanted to display the current user photo in a imageview, but it didnt worked for me. i think i am doing something wrong. the best thing will be to show the code i tried to use. The Method which should do the display change is updateDisplayUser but the image view doesnt change . (Still displaying blue backgroundColor)

Thx for help guys

ProfileMainPage();
 
function ProfileMainPage() { 
 
   var imageViewUser;
 
   updateDisplayedUser();
 
 
 
 
 
 
 
        this.imageViewUser = Titanium.UI.createImageView({
            width : 150,
            height : 150,
            backgroundColor : '#0000ff'
        });
 
 
 
    }
 
 
 
    function updateDisplayedUser() {
 
        var lThis = this;
 
        Cloud.Users.showMe(function(userCallback) {
            if(userCallback.success) {
                var lUser = userCallback.users[0];
 
                lThis.imageViewUser.image = lUser.photo;
                Titanium.API.info('Photo: ' + lUser);
                Titanium.API.info('Photo: ' +lUser.photo );
 
            } else {
                alert('Error:\\n' + ((userCallback.error && userCallback.message) || JSON.stringify(userCallback)));
            }
        });
    }
 
}

— asked 10 months ago by Dominik Heim
2 Comments
  • I'm just glad that this != that

    — commented 10 months ago by Stephen Feather

  • Titanium.API.info('Photo: ' + lUser);
    Titanium.API.info('Photo: ' +lUser.photo );
    And what does this show you in the console?

    — commented 10 months ago by Stephen Feather

1 Answer

moved some things around and made some changes to ensure you had the right context. You might want to include all of the code in the sample.js so we can just run your app to see exactly what your problem is.

function ProfileMainPage() {
    var that = this;
 
    that.imageViewUser = Titanium.UI.createImageView({
        width : 150,
        height : 150,
        backgroundColor : '#0000ff'
    });
 
    // now call method
    updateDisplayedUser.call(that);
 
}
 
function updateDisplayedUser() {
 
    var that = this;
 
    Cloud.Users.showMe(function(userCallback) {
        if (userCallback.success) {
            var lUser = userCallback.users[0];
 
            that.imageViewUser.image = lUser.photo;
            Titanium.API.info('Photo: ' + lUser);
            Titanium.API.info('Photo: ' + lUser.photo);
 
        } else {
            alert('Error:\\n' + ((userCallback.error && userCallback.message) || JSON.stringify(userCallback)));
        }
    });
}
 
ProfileMainPage();

Your Answer

Think you can help? Login to answer this question!