晚上好。我是Android开发的初学者。我不想弄脏我的主要活动课程,这就是为什么我要使用一些外部课程(我可以为某些外部课程提供“这个”吗?)。我的问题可能很简单。我想显示 AlertDialog。所以我的课
public class Dialogs {
public static void exitActivity(Context c ){
AlertDialog.Builder builder = new AlertDialog.Builder(c);
//Construct dialog
builder.setMessage("Are your sure you want to exit?");
builder.setCancelable(false);
//Listener for yes button
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
FifteenActivity.c.finish(); ////<<< Here is an error >>>>//
}
});
//Listener for no button
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.newGame:
restart();
return true;
case R.id.settings:
return true;
case R.id.info:
return true;
case R.id.help:
return true;
case R.id.exit:
Dialogs.exitActivity(this);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
在外部课程中创建所有菜单是一种“好习惯”吗?