當用戶點擊包含在我的主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