John Gaby wrote:
> I am trying to create a ListView and add it to a custom ViewGroup.
> Here is my code:
> 
> public class HelloAndroid extends Activity
> {
>     private static final String[] PHOTOS_NAMES = new String[] {
>         "Lyon",
>         "Livermore",
>         "Tahoe Pier",
>         "Lake Tahoe",
>         "Grand Canyon",
>         "Bodie"
>     };
> 
> 
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
> 
>         TextView tv = new TextView(this);
>         MyViewGroup vg = new MyViewGroup(this);
>         ListView lv = new ListView(this);
> 
>         tv.setText("Some Text");
>         tv.layout(0, 0, 200, 40);
>         vg.addView(tv);
> 
>         lv.layout(0, 40, 200, 200);
> 
>         final ArrayAdapter<String> adapter = new
> ArrayAdapter<String>(this,
>                 android.R.layout.simple_list_item_1, PHOTOS_NAMES);
> 
>         lv.setAdapter(adapter);
> 
>         vg.addView(lv);
> 
>         setContentView(vg);
>     }
> }
> 
> When I do this, I see the "Some Text" TextView (which I also am adding
> to my ViewGroup), but I don't see the ListView.  Now if I set the
> ListView as the content view, (i.e. setContentView(lv)) it shows up.
> 
> Does anyone have any idea what I am doing wrong?

1. Do not call layout() on the ListView.

2. Get this whole example working without MyViewGroup, perhaps replacing
it with a LinearLayout. Then, substitute in MyViewGroup and work on
getting that behaving properly.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_Beginning Android 2_ from Apress Now 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