Multiple TableViews with SearchBar in ScrollableView causes crash on Android

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

I've come across a situation where having multiple TableViews in a ScrollableView causes my app to crash when running on Android. The crash only happens after a TableView that uses a search bar has been added to the ScrollableView. All is well if none of the TableViews make use of the table.search property. Does anyone have a workaround for this?

Here is an app.js that demonstrates the problem.

var win = Titanium.UI.createWindow({
    title: 'My Root Window',
    exitOnClose: true
});
var view1 = Ti.UI.createView({ backgroundColor:'#123' });
var view2 = Ti.UI.createView({ backgroundColor:'#246' });
var scrollableView = Ti.UI.createScrollableView({
  views:[],
  showPagingControl:false
});
 
win.add(scrollableView);
 
var data = [
    Ti.UI.createTableViewRow({className: 'testRow',hasChild:true,title:'Table 1 Row 1'}),
    Ti.UI.createTableViewRow({className: 'testRow',hasDetail:true,title:'Table 1 Row 2'})
];
 
var tableview = Titanium.UI.createTableView({
    top:0,
    data:data,
    search: Titanium.UI.createSearchBar({
        showCancel:true,
        height:43
    })
});
 
view1.add(tableview);
 
var data2 = [
    Ti.UI.createTableViewRow({className: 'testRow',hasChild:true,title:'Table 2 Row 1'}),
    Ti.UI.createTableViewRow({className: 'testRow',hasDetail:true,title:'Table 2 Row 2'})
];
 
var tableview2 = Titanium.UI.createTableView({
    top:0,
    data:data2,
    search: Titanium.UI.createSearchBar({
        showCancel:true,
        height:43
    })
});
 
view2.add(tableview2);
 
win.open();
setTimeout(function(){
    scrollableView.addView(view1);
}, 2000);
 
setTimeout(function(){
    scrollableView.addView(view2); // <-- Causes an exception on Android
}, 4000);
This code works fine on iOS but fails on the following configurations.

My Setup

OS: Mac OSX 10.7.2

Mobile SDK: 1.7.5, 1.8.0.1, 1.8.1

Android Devices:

  • HTC EVO 4G Android 2.2 (w/HTC Sense)

  • Samsung Nexus S Android 4.0.3

  • Emulator (platform: 2.2, API: 8)

All tests result in the following exception:

Sending event: exception on thread: main msg:java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

— asked 1 year ago by Mahlon Gumbs
2 Comments
  • you list multiple SDKs, which one are you experiencing this error on

    — commented 1 year ago by Aaron Saunders

  • I get the error on all three of the SDKs listed.

    — commented 1 year ago by Mahlon Gumbs

2 Answers

Have had the same problem with multiple tableViews in a scrollableView.

The only way I have found that it will not crash is if I add the Search view to a parent window containing the scrollableView and add listeners for the tableView's interaction.

After that it is important to note that animating the search view so that it is visible should the keyboard obscure it, will also cause a crash. This is only an issue in iOS since Android will animate the search view.

Would be nice if the jira ticket were addressed. This has been a problem for a long time now.

Your Answer

Think you can help? Login to answer this question!