Search code examples
androidtitaniumappcelerator

Android - Appcelerator : Add n elements simultaneously


Titanium SDK 5.5.1.G.A

I'm converting an iOS app to be compatible with Android.

On iOS if i do this :

var v1 = Ti.UI.createView({
    width : 10,
    height : 10,
    opacity : 0
});
var v2 = Ti.UI.createView({
    width : 10,
    height : 10,
    opacity : 0
});

window.add(v1,v2);

The 2 view are added correctly. But on Android only the first view. It's a bug or the normal behavior on this platform?

For Android i have to do this :

window.add(v1);
window.add(v2);

Solution

  • On iOS Ti.UI.View.add() accepts an array of views: https://github.com/appcelerator/titanium_mobile/blob/0357b4796abf0032485018fac42614a94f826c9b/iphone/Classes/TiViewProxy.m#L149

    On Android it does not: https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java#L181

    Related question on Q&A: https://community.appcelerator.com/topic/3075/unable-to-add-array-of-views-to-parent-view-on-android

    AFAIK Developer Team are going to add array support for Android in v 6.1.0 of Titanium SDK.