Add the following line after "ListView myTextView = new ListView
(this);"

    myTextView.setId(android.R.id.list);


--
Jack Ha
Open Source Development Center
・T・ ・ ・Mobile・ stick together

The views, opinions and statements in this email are those of
the author solely in their individual capacity, and do not
necessarily represent those of T-Mobile USA, Inc.



On Jul 26, 3:44 am, RainBow <[email protected]> wrote:
> Hi,
>
> I am trying to use the LinearLayout class directly in my code , rather
> than using XML.
>
> If I use the XML code, it works fine.
>
> However, if I supply my own code in OnCreate() of ListActivity-derived
> class, it crashes.
>
> Here is the XML code and corresponding Java code that I wanna write.
> Could someone tell me whats wrong with my code?
>
> // XML Code : This works just fine
>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>     android:orientation="vertical"
>     android:layout_width="fill_parent"
>     android:layout_height="fill_parent">
>
>      <ListView android:id="@android:id/list"
>             android:layout_width="fill_parent"
>             android:layout_height="fill_parent"
>             android:drawSelectorOnTop="false"/>
>
>     </LinearLayout>
>
> // Corresponding Java Code : this crashes at setContentView() call:
>
>         LinearLayout ll = new LinearLayout(this);
>         ll.setOrientation(LinearLayout.VERTICAL);
>
>         ListView myTextView = new ListView(this);
>
>         int lHeight = LinearLayout.LayoutParams.FILL_PARENT;
>         int lWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
>         ll.addView(myTextView, new LinearLayout.LayoutParams(lHeight,
> lWidth));
>
>         setContentView(ll); //<------ this line crashes
>
> Thanks,
> ~Viren
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to