gpt4 book ai didi

java - 关闭对话框后如何从对话框中获取数据?

转载 作者:行者123 更新时间:2023-12-01 18:40:55 24 4
gpt4 key购买 nike

我尝试将对话框中的数据获取到 TextView 中,但出现应用程序无法看到 TextView 的错误,因为 TextView 位于对话框后面...我点击按钮后就会出现

backpackDialog = new Dialog(MainActivity.this);
backpackDialog.setTitle("Backpack");
backpackDialog.setContentView(R.layout.backpack_layout);
window = backpackDialog.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
backpackDialog.show();

// and after i click to dissmis the dialog...
useItemButton.setOnClickListener(new View.OnClickListener()
{ @Override public void onClick(View view)
{
// here is the problem...
intPlayerHealth = intPlayerHealth + 20;
->playerHealthText.setText(intPlayerHealth);<-
backpackDialog.dismiss();
}
});

在我关闭对话框以重新启动 Activity 或类似的操作以刷新我的主要 Activity 布局后,我该如何进行操作,这样我就可以获得我的textView的新值,并且也不会出现无法执行的错误参见textView,谢谢

最佳答案

写起来很简单 official documentation

@Override
public void onDismiss(@NonNull DialogInterface dialog) {
// here is the problem...
// You can write you action here
super.onDismiss(dialog);
}

关于java - 关闭对话框后如何从对话框中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59933648/

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