Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9100] Android: When trying to remove the contents of a window, the window doesn't have any children

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-08-01T04:42:21.000+0000
Affected Version/sn/a
Fix Version/sSprint 2012-13 Core, Release 2.1.1, Release 3.0.0
ComponentsAndroid
LabelsSupportTeam, core, module_window, parity, qe-testadded, release-note
ReporterMauro Parra-Miranda
AssigneeAllen Yeung
Created2012-05-10T13:59:44.000+0000
Updated2013-12-10T06:16:04.000+0000

Description

Problem Description

In the attempt of creating a function that will remove all the elements inside a view or window, we are getting a different behavior between android and ios, where in android, if you have a window with several attached elements, it will say that there is no children.

Actual Results

There is no children attached to the window, even if there are.

Expected results

The same behavior than in iOS.

Test Case

1. Create mobile project. 2. Paste this into app.js

var win = Ti.UI.createWindow();
var view = Ti.UI.createView();
var label = Ti.UI.createLabel();
var label2 = Ti.UI.createLabel();
var image = Ti.UI.createImageView({
	url:'KS_nav_ui.png',
});
var view2 = Ti.UI.createView(); 
view2.add(label);
view2.add(label2)
view.add(view2);
view.add(image);
win.add(view);
win.open();

function do_clean(e,c){
	clean(c);
	e.remove(c);
	Ti.API.info( 'Deleted child at do_clean' );
	return;
}

function clean(e){	
	Ti.API.info( 'Number of children: ' + e.children.length );
	if(e.children){
		for(var i = 0; i<e.children.length;i++){
			do_clean(e, e.children[0]);
		}
	} else { 
		return; 
	}
}

clean(win);

3. Run this in ios, check the logs. 4. Run this in Android, check the logs.

HD Discussion

http://support-admin.appcelerator.com/display/APP-428357

Extra info

This is an attempt to do a cleaning of any window, view, tableview, etc.

Comments

  1. Ivan Skugor 2012-05-11

    This issue is related to TIMOB-7482
  2. Ivan Skugor 2012-06-12

    Btw, here is what does not work on Android: https://gist.github.com/2867975 For some reason, "_children" property does what "children" does in case of a window. "children" property on the other hand does nothing.
  3. Allen Yeung 2012-06-19

    Updated test case:
       var win = Ti.UI.createWindow();
       var view = Ti.UI.createView();
       var label = Ti.UI.createLabel();
       var label2 = Ti.UI.createLabel();
       var image = Ti.UI.createImageView({
           url:'KS_nav_ui.png',
       });
       var view2 = Ti.UI.createView(); 
       view2.add(label);
       view2.add(label2)
       view.add(view2);
       view.add(image);
       win.add(view);
       
       function do_clean(e,c){
           clean(c);
           e.remove(c);
           Ti.API.info( 'Deleted child at do_clean' );
           return;
       }
       
       function clean(e){  
           Ti.API.info( 'Number of children: ' + e.children.length );
           if(e.children){
               var length =e.children.length;
               for(var i = 0; i<length;i++){
                   do_clean(e, e.children[0]);
               }
           } else { 
               return; 
           }
       }
       
       win.addEventListener('open',function(){
       	clean(win);
       });
       
       win.open();
       
    Expected results: In both iOS and android, we should return something like
       I/TiAPI   (26605): Number of children: 1
       I/TiAPI   (26605): Number of children: 2
       I/TiAPI   (26605): Number of children: 2
       I/TiAPI   (26605): Number of children: 0
       I/TiAPI   (26605): Deleted child at do_clean
       I/TiAPI   (26605): Number of children: 0
       I/TiAPI   (26605): Deleted child at do_clean
       I/TiAPI   (26605): Deleted child at do_clean
       I/TiAPI   (26605): Number of children: 0
       I/TiAPI   (26605): Deleted child at do_clean
       I/TiAPI   (26605): Deleted child at do_clean
       
    Actual result: In android, we get a single "Number of children: 0" and that's it.
  4. Neha Chhabra 2012-07-17

    Environment used for verification - Tested with Titanium SDK: 2.1.1.v20120716180600 Tested with Titanium  Studio: 2.1.1.201207161421 Device - Android Emulator 2.3.3 Machine OS - MAC 10.7.3
  5. Arthur Evans 2012-07-23

    Reopening to fix labels.
  6. Arthur Evans 2012-07-23

    Updated labels.
  7. Neha Chhabra 2012-08-01

    Reopening issue to update labels
  8. Shameer Jan 2013-12-10

    Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4967

JSON Source