Android——从 findViewById(R...) 分配的 SurfaceView 不允许访问自定义字段
我有一个程序,它有效。我正在尝试获取在 XML 资源中声明的 SurfaceView 之一,以便可以在 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 '
搞什么?提前致谢!
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!
您将视图声明为 SurfaceView。您应该使用您的类名来声明它。
You are declaring the view as a SurfaceView. You should declare it using your class name.