How to add a property in android

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

Hi all , I have a problem about add property in android.

As in iPhone, I can create a new property in a class such as :

var view = Ti.UI.createView({

  backgroundColor:'#000',

  classname:'test'

});

I can access new property "classname" anywhere in iPhone.

But in android, I can't get the value of classname when I addEventListener , for example :

scrollView.addEventListener('scroll', function(e) {

  alert('classname : ' + e.view.classname);

});

Does there any problem about my usage or there are any way to get classname?

Thanks for your helping.

— asked 2 years ago by Sky Chen
0 Comments

2 Answers

Accepted Answer

Try this:

Ti.API.info( JSON.stringify(e) );
 
Ti.API.info( JSON.stringify(e.view) );
It'll log out e with all properties it has.

Hope that help,

Minh

— answered 2 years ago by Minh Nguyen
answer permalink
6 Comments
  • Use the method above could get the event information and view type.({"type" : "scroll","index":1,"currentPage":1} and "[Ti.UI.ScrollableView]")

    But when I try to get classname by JSON.stringify(e.view.classname), it still show "undefined".

    Thanks for your answer.

    — commented 2 years ago by Sky Chen

  • Could you please share more code so that we can debug/help with?

    — commented 2 years ago by Minh Nguyen

  • var win = Ti.UI.createWindow({
        backgroundColor:'#000'
    });
    var view1 = Ti.UI.createView({
        backgroundColor:'#000',
        classname:'test1'
    });
    var view2 = Ti.UI.createView({
        backgroundColor:'#000',
        classname:'test2'
    });
    var scrollView = Ti.UI.createScrollableView({
        views:[view1,view2],
        showPagingControl:false
    });
    scrollView.addEventListener('scroll', function(e) {
        Ti.API.debug('e : ' + JSON.stringify(e));
        Ti.API.debug('view : ' + JSON.stringify(e.view));
        Ti.API.debug('classname : ' + JSON.stringify(e.view.classname));
    })
    win.add(scrollView);
    win.open();
    I need the classname to identify what kind of view it is.

    Thanks for your reply.

    — commented 2 years ago by Sky Chen

  • Show 3 more comments

What happens when you try e.source.classname?

Your Answer

Think you can help? Login to answer this question!