当用户点击包含在我的主Activity中的SurfaceView时,我将项目存储到ArrayList中。从SurfaceView子类传递ArrayList到Activity
主要活动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>
onTouch在SurfaceClass
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN)
{
int touchX = (int)(motionEvent.getX());
int touchY = (int)(motionEvent.getY());
Point point = new Point(touchX, touchY);
mItemsClicked.add(point);
for (int i = mItems.size()-1; i >= 0; i--)
{
Item item = listOfItems.get(i);
inventory.add(item);
}
invalidate();
}
return false;
}
我怎么会去能够使用这种库存的ArrayList我的主要活动中,为了话传递的ArrayList,这样我能够简单地从我的活动中点击一个按钮,并且例如记录该ArrayList控制台。
您是否已将Surface类定义为Activity类的内部类? –
我有Surface类,因为它是自己的类 – Jenna25