//选择关卡
public int chooseModel() {
new AlertDialog.Builder(this)
.setTitle("选择查看排行榜关卡")
.setIcon(android.R.drawable.ic_dialog_info)
.setSingleChoiceItems(new String []
{"经典模式: 关卡1","经典模式:关卡2","经典模式:关卡3","经典模式:关卡4","经典模式:关卡5",
"疯狂模式: 关卡1","疯狂模式: 关卡2","疯狂模式: 关卡3","疯狂模式: 关卡4","疯狂模式: 关卡5"},
0,
new DialogInterface.OnClickListener() {
int n;
public void onClick(DialogInterface dialog, int which) {
//dialog.dismiss();
switch (which) {
case 0: n = 0;
break;
case 1: n = 1;
break;
case 2: n = 2;
break;
case 3: n = 3;
break;
case 4: n = 4;
break;
default:
break;
}
SharedPreferences preference = getSharedPreferences("n", MODE_PRIVATE);
Editor editor = preference.edit();
editor.putInt("n", n);
editor.commit();
}
}
)
.setNegativeButton("取消", null)
.setPositiveButton("确定", null)
.show();
SharedPreferences preference = getSharedPreferences("n", MODE_PRIVATE);
return preference.getInt("n",0);
}
在 setNegativeButton()中 我们还可以对其添加监听器
前面的博客中已经出现过 ,这里不再写了
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。