reposted here from the android developers group because this is a
beginner question; sorry about the duplication

I got a simple layout working and displaying by only editing the
layout xml.  Basically it was the layout below without my BoardView in
there.  Now I'm trying to write my own View class to handle various
onFoo() events, using LunarLander as an example.  Here's my simple
layout and class:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

        <com.my.package.BoardView
      android:id="@+id/board"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>

        <TextView  android:id="@+id/TopText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="play area"
        />
        <LinearLayout android:id="@+id/rowButtons"
                android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        >
                <Button android:id="@+id/btnPlay"
                        android:text="Play"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                <Button android:id="@+id/btnInfo"
                        android:text="Info"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                <Button android:id="@+id/btnSetup"
                        android:text="Setup"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
        </LinearLayout>

        <TextView  android:id="@+id/InfoText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="screen size:"
        />

</LinearLayout>

public class BoardView extends SurfaceView {

        public BoardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        }

        @Override
        protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
                // TODO Auto-generated method stub
                super.onSizeChanged(w, h, oldw, oldh);

                TextView info = (TextView)
findViewById(R.id.InfoText);
                //info.setText("width : " + w + ", height : " + h);
        }

}

When I first ran it, it blew up with a NPE in onSizeChanged.  So at
least I knew it was getting there.  I commented out the info.setText
line and it ran fine, but the view is blank on the screen.  Why are
the various TextViews and buttons not visible?  I couldn't find any
guidelines in the docs as to how/where to place your View class in the
layout.xml.

--~--~---------~--~----~------------~-------~--~----~
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