When I first ran it with my View class in the layout xml, it blew up with a NPE in onSizeChanged. So at
least I knew it was getting into my View class. 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.
I'd appreciate any help. Thanks.
Here's my simple layout and class:
Using xml Syntax Highlighting
- <?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>
Parsed in 0.005 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- 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);
- }
- }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


