gpt4 book ai didi

java - 向上导航确认

转载 作者:行者123 更新时间:2023-11-29 05:04:22 24 4
gpt4 key购买 nike

我有一个记分应用程序,其中的父 Activity 允许用户输入自定义团队名称。

enter image description here

然后用户可以在游戏中记分。

enter image description here

如果用户在记分 Activity 中点击后退按钮(以返回团队选择器 Activity ),由于得分数据丢失,我实现了确认:

@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Return to team selector")
.setMessage("Returning to the team selector will reset the scores. Are you sure " +
"you want to continue?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}

})
.setNegativeButton("No", null)
.show();
}

我想在用户“向上导航”到父项(即团队选择器)时实现类似的确认,因为得分数据也会丢失。但是,我在这样做时遇到了问题。

是否有类似的“onUpPressed”函数我没有找到?任何其他有关我如何解决此问题的指导都将受到赞赏。

最佳答案

是的,你可以做到...

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
}
return super.onOptionsItemSelected(item);
}

关于java - 向上导航确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30930293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com