我目前正在尝试在 android 中创建一个 3d 游戏,但我正在努力解决一些问题。
在我的游戏中单击方向按钮后的某个时间点,我尝试访问一个 ArrayList,但我的 ArrayList(之前填充的)似乎现在是空的。
那是线程问题吗?
@Override
public void Update(ArrayList<ArrayList<IModel>> Database) {
this.DataBase = Database;
System.out.println("---> " + this.DataBase.get(0)); //WORKING
}
Button up_btn = (Button) findViewById(R.joystick.up);
up_btn.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
System.out.println("--------->" + DataBase.get(0)); //NOT WORKING
}
});
这是我的整个代码;
public class PlayerController extends Activity implements IController
{
//Properties
private ArrayList<ArrayList<IModel>> DataBase = null;
private GLSurfaceView mGLView;
//Virtual
@Override public void Update(ArrayList<ArrayList<IModel>> Database)
{
this.DataBase = Database;
System.out.println("---> " + this.DataBase.get(0)); //WORKING
}
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.mGLView = new MySurfaceView(this);
LayoutInflater inflater = getLayoutInflater();
this.getWindow().addContentView(this.mGLView, new ViewGroup
.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
this.getWindow().addContentView(inflater.inflate(R.layout.footer, null), new ViewGroup
.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
this.getWindow().addContentView(inflater.inflate(R.layout.play, null), new ViewGroup
.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, (int)80));
//Joystick buttons
Button up_btn = (Button) findViewById(R.joystick.up);
up_btn.setOnClickListener(new View.OnClickListener()
{
@Override public void onClick(View v)
{
System.out.println(">>>>>" + DataBase.get(0)); //NOT WORKING..
//UpMotionListener();
}
});
}
@Override protected void onPause()
{
super.onPause();
mGLView.onPause();
}
@Override protected void onResume()
{
super.onResume();
mGLView.onResume();
}
public void UpMotionListener()
{
//System.out.println(">>>>>>>>>" + DataBase.get(0)); //NOT WORKING
}