Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将ArrayList从SurfaceView子类传递给Activity_Java_Android_Arraylist - Fatal编程技术网

Java 将ArrayList从SurfaceView子类传递给Activity

Java 将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

当用户单击包含在我的主要活动中的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_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();