How to add a dynamically created LinearLayout to a ScrollView?

I want to dynamically add some widgets like so:

LinearLayout llay = new LinearLayout(this); 
llay.setOrientation(LinearLayout.HORIZONTAL); 

LinearLayout.LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
llp.weight = 1.0f; 

CheckBox cb = new CheckBox(getApplicationContext()); 
cb.setText("1"); 
cb.setLayoutParams(llp); 
llay.addView(cb);

ScrollView svh = (ScrollView) findViewById(R.id.scrollViewHost);
svh.AddView(llay);

...but I'm getting, "The method AddView(LinearLayout) is undefined for the type ScrollView"

So what should I do to add the LinearLayout to the existing ScrollView?

Upvotes: 2

Views: 4908

Answers (3)

Shreyash Mahajan
Shreyash Mahajan

Reputation: 23596

Is your problem solved by the dmon's answer?

Be sure that yout have correct the spealing of the addView(). java is case sensitive. addView() and AddView() both are different thing.

Also make sure that your are adding ScrollView to the OneParent Layout. As Because you can able to add the ScrollView to the Only One Parent Layout.

So, supose you have two layout like LinearLayout and RelativeLayout and if you provide One ScrollView to the both layout then it will arrise error.

you have to add another layout as parent of both the layout and then add ScrollView to that parent layout.

Hope you got the point.

Thanks.

Enjoy. :)

Upvotes: 1

Roger Heim
Roger Heim

Reputation: 89

It's addView(), not AddView(). Or was that just a typo in your question?

Upvotes: 1

dmon
dmon

Reputation: 30168

Because Java is case sensitive? AddView() != addView(). Also (though not the root of the problem), note that a ScrollView can only have one child.

Upvotes: 3

Related Questions