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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将视图声明为 SurfaceView。您应该使用您的类名来声明它。
You are declaring the view as a SurfaceView. You should declare it using your class name.