Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4348] Android - ScrollableView + TableViews with Searchbars crashes app

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2013-04-26T09:01:30.000+0000
Affected Version/sRelease 1.7.0, Release 2.0.1
Fix Version/sRelease 3.1.0
ComponentsAndroid
Labelsn/a
ReporterPedro Enrique
Assigneejithinpv
Created2011-06-08T07:38:41.000+0000
Updated2017-03-31T21:03:08.000+0000

Description

If I create a scrollable view with TableViews and those TableViews have a search bar, the app crashes with the console saying:
java.lang.IllegalStateException: The specified child already has a parent.
You must call removeView() on the child's parent first.
Here is a very simple example code
var win = Titanium.UI.createWindow({
    backgroundColor:'#fff'
});

var tv = function(){
	var data = [ {title:'1'}, {title:'2'} ];
	var t = Ti.UI.createTableView({
		search:Ti.UI.createSearchBar({
			height:35
		}),
		data:data
	});
	
	return t;
};

var sc = Ti.UI.createScrollableView({
	views:[tv(), tv()]
});

win.add(sc);

win.open();

Comments

  1. Junaid Younus 2012-05-15

    Tested on 2.0.1GA2 using a Samsung Galaxy S2, I was unable to reproduce the issue. Ticket closed.
  2. Mahlon Gumbs 2012-05-22

    Guys, this bug is only partly resolved. The issue still exist if you use the addView method of the scrollable to add "searchable tableviews". It looks like populating the views collection as part of the scrollable's config has been fixed, but addView still has the same problem as seen in this code example:
       var win = Titanium.UI.createWindow({
           backgroundColor:'#fff'
       });
        
       var tv = function(){
           var data = [ {title:'1'}, {title:'2'} ];
           var t = Ti.UI.createTableView({
               search:Ti.UI.createSearchBar({
                   height:35
               }),
               data:data
           });
            
           return t;
       };
        
       var sc = Ti.UI.createScrollableView({
           views:[]
       });
       
       win.add(sc);
        
       win.open();
       
       //Simulate view being added as the result of a user action (perhaps a button's click event)
       setTimeout(function(){
       	sc.addView(tv());
       }, 2000);
       
       //Simulate a second view being added as the result of a user action (perhaps a button's click event)
       setTimeout(function(){
       	sc.addView(tv()); //<-- causes exception mentioned above
       }, 4000);
       
  3. Mahlon Gumbs 2012-05-22

    Forgot to mention this latest test was done on 2.0.1GA2 using a Samsung Nexus S running Android 4.0.4.
  4. Neeraj Gupta 2012-05-22

    Reopened this ticket based on the recent report.
  5. Sebastien 2012-06-26

    I have the same issue with addView. I think the problem is in processProperties method in TiUITableView. When we have a searchbar we reuse it with this line : TiUISearchBar searchBar = (TiUISearchBar)searchView.getOrCreateView(); but we always do layout.addView(searchBar.getNativeView(), p);
  6. jithinpv 2013-04-26

    cannot reproduce Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Android Emulator: Android SDK version: 2.2
  7. Lee Morris 2017-03-31

    Closing ticket as fixed.

JSON Source