我正在制作一个允许用户选择不同类型的游戏,在MainActivity中将有一个警报对话框供用户选择。 有2个元素(speed_1和speed_2)是影响GameActivity中难度的数字将数据更改为其他活动
我想让用户在Alert对话框中选中“Easy”,speed_1和speed_2将变为1(在GameActivity)
如果在警告对话框中,用户检入 “困难”,speed_1和speed_2将更改为3(在GameActivity)
谢谢!
void generateLevelListDialog() {
// Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
// Specify the list in the dialog using the array
builder.setTitle("Difficulty").setItems(R.array.levels_array,
new DialogInterface.OnClickListener() {
// Chain together various setter methods to set the list
// items
// The index of the item selected is passed by the parameter
// which
public void onClick(DialogInterface dialog, int which) {
//switch to game activity
Intent gameIntent = new Intent(MainActivity.this, GameActivity.class);
//change ball speed and racket length
switch (which) {
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
//start activity
startActivity(gameIntent);
}
});
//create and show list dialog
AlertDialog dialog = builder.create();
dialog.show();
}
谢谢您的回复,当运行应用程序时没有错误,但在该应用程序中,当我小鸡“轻松”时,游戏发生冲突,您有任何建议吗? – aaaabbbb
检查你的IDE中的logcat /输出窗口,它应该显示一个异常堆栈跟踪,它会给你一个线索。 – Mikhail