1
votes

I have a program, it works. I'm trying to get one of the SurfaceViews that was declared in an XML resource to be accessible in an Activity class. The surfaceview is assigned alright and allows access the SurfaceView methods/elements, but not my custom ones. How do I access the custom elements?

public class main extends Activity {
  SurfaceView viewer;

  public void onCreate(...) {
    ...
    //Successfully assigns object to viewer
    viewer = (SurfaceView)findViewById(R.id.Viewer); 
  }

  void someMethod(){
    viewer.doSomethingRad(); //FAIL
  }
}
//////////////
public class Viewer extends SurfaceView... {
  ....
}
/////////////Main.xml
...
~view class="com.ballroll.Viewer" 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" 
  android:id="@+id/Viewer" 
  android:text="Viewer"~
~/view~
//I don't know how to escape '

WTF? Thanks in advance!

1

1 Answers

2
votes

You are declaring the view as a SurfaceView. You should declare it using your class name.

 Viewer viewer;

  public void onCreate(...) {
    ...
    //Successfully assigns object to viewer
    viewer = (Viewer)findViewById(R.id.Viewer); 
  }