myIP wrote:
> How can I attach 2 or more children (Views) to an Activity?  I can't
> seem to find a way to attach these CheckBoxes to the main Activity.
> Only one of them gets rendered.
> 
> public class AddTwoViews extends Activity
> {
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState)
>     {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
> 
>         LinearLayout layout = (LinearLayout) findViewById
> (R.layout.main);
>               LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
> LinearLayout.LayoutParams.WRAP_CONTENT,
>                                                                               
>                                                                 
> LinearLayout.LayoutParams.WRAP_CONTENT);
>         CheckBox alphaCheckBox = new CheckBox(this);
>         CheckBox redChannelCheckBox = new CheckBox(this);
> 
>         setContentView(alphaCheckBox, p);
>         setContentView(redChannelCheckBox, p);
>     }
> }

setContentView() sets the view for the activity. What you are doing is 
setting that three times: once for the LinearLayout and once for each of 
your checkboxes.

That's probably not your intent.

What you probably want is to add your checkboxes to the LinearLayout.

This is much more straight-forward if you use the layout XML files.

If you insist upon doing this in Java (e.g., you were attacked by an XML 
file as a young child), you'll want to use addView() on the LinearLayout 
to add each of the checkboxes in turn.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to