我有一个程序,它有效。我试图让一个在XML资源中声明的SurfaceViews可以在Activity类中访问。 surfaceview被指定为正常,允许访问SurfaceView方法/元素,但不能访问我自定义的方法/元素。如何访问自定义元素?
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?提前谢谢!
答案 0 :(得分:2)
您将视图声明为SurfaceView。您应该使用您的班级名称声明它。
Viewer viewer;
public void onCreate(...) {
...
//Successfully assigns object to viewer
viewer = (Viewer)findViewById(R.id.Viewer);
}