Ian Vink
Ian Vink

Reputation: 68750

Android: Adding a Button to a ScrollView programmatically

I have a ScrollView containing a number of buttons and textviews.

I wish to insert a new button midway (index 3)on the scroll view but get the error, "ScrollView can host only one direct child"

Is this not possible?

Button b = new Button(this);
scrView.AddView(b,3);

????

Upvotes: 0

Views: 3219

Answers (2)

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

No you can't add more then one view in scollview as you know now "ScrollView can host only one direct child"

you would definalty have a linear layout in scollview where you would have added other buttons previously so add new one in that......

Upvotes: 0

DeeV
DeeV

Reputation: 36035

Put the sub-views in a layout like LinearLayout or RelativeLayout then put the layout in the ScrollView. Add your views to the layout rather than the ScrollView.

Upvotes: 5

Related Questions