Reputation: 4325
I have build a layout programmatically in Android (a treeview) and now I'd like to add to the built view a topbar (topbar.xml).
So what I need is instead of:
setContentView(scroll)
Something like:
inflateInMyViewCalledScroll(topbar.xml)
setContentView(scroll)
Thanks for your suggestions
Upvotes: 3
Views: 4243
Reputation: 5511
ScrollView can only have one direct child.
So you have to do something like this:
<ScrollView>
<LinearLayout android:id="@+id/foo" android:orientation="vertical">
<!-- youll add topbar here, programmatically -->
<other things/>
</LinearLayout/>
</ScrollView>
And then at runtime, you'll inflate topbar
View topbar = getLayoutInflater().inflate(R.layout.topbar, null);
and add it as the first index in foo
foo.addView(topbar, 0);
Upvotes: 5
Reputation: 1006549
Inflate topbar.xml
using LayoutInflater
, putting the results into scroll
:
getLayoutInflater().inflate(R.layout.topbar, scroll);
Upvotes: 6