farm ostrich
farm ostrich

Reputation: 5959

Android -- SurfaceView assigned from findViewById(R...) won't allow access to custom fields

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!

Upvotes: 1

Views: 1500

Answers (1)

slund
slund

Reputation: 6397

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); 
  }

Upvotes: 2

Related Questions