【发布时间】:2011-10-19 03:03:08
【问题描述】:
我有一个 AlertDialog,我只希望在单击“确定”后启动下一个 Activity。问题出在我的方法中,我的意图附加了局部变量,我无法放入 onCreateDialog 方法。
//local variable created
ArrayList<String> students = new ArrayList<String>();
for(int i=0; i<studentList.size(); i++){
students.add(studentList.get(i).getName());
}
AlertDialog.Builder alertDialog = new AlertDialog.Builder(
new ContextThemeWrapper(this, R.style.popup_theme));
alertDialog.setTitle("Select Game");
alertDialog.setPositiveButton("3x3", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//I want the new Activity to start only after user clicks ok.
Intent intent=new Intent(getApplicationContext(),NewActivity.class);
//Local variable, undefined, cannot reference
intent.putStringArrayListExtra("students", students);
startActivity(intent);
finish();
return;
}
});
alertDialog.show();
有什么方法可以阻止showDialog() 之后的代码运行,直到用户单击“确定”?我有需要放入意图中的局部变量。
【问题讨论】:
-
你的代码看起来是正确的,当点击按钮时它会启动活动
标签: android android-activity android-alertdialog