Java 将ArrayList从SurfaceView子类传递给Activity
当用户单击包含在我的主要活动中的SurfaceView时,我正在将项目存储到ArrayList中 主要活动XMLJava 将ArrayList从SurfaceView子类传递给Activity,java,android,arraylist,Java,Android,Arraylist,当用户单击包含在我的主要活动中的SurfaceView时,我正在将项目存储到ArrayList中 主要活动XML <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_heig
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<newProject.SurfaceClass
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/spaceField" />
</LinearLayout>
我如何才能在我的主要活动中使用此清单ArrayList,以便文字传递该ArrayList,以便我能够从活动中单击一个按钮并记录该ArrayList控制台。例如。活动中有一个视图。为什么不在SurfaceView有权访问并可以填充的活动中创建全局成员变量ArrayList,然后在需要时从活动中读取该信息。使用简单的for each循环。可以在返回列表的surface类中添加公共方法
getMyList()....
在你的主要活动中。。使用“按id查找视图”获取曲面类的对象
mySurfaceView= findVi....
然后
mySurfaceView.getMyList();
您是否在活动类中将表面类定义为内部类?我将表面类定义为自己的类
mySurfaceView.getMyList();