gpt4 book ai didi

java - 无法解析完成方法——从 Android Studio 方法调用

转载 作者:行者123 更新时间:2023-11-29 00:03:01 24 4
gpt4 key购买 nike

安卓工作室 3.0.1

它在 QAnswerQuestion.java 代码中工作

List<Integer> wrongList = UIResponse.checkAnswer(list);
if (wrongList.size() == 0)
{
new AlertDialog.Builder(QAnswerQuestion.this).setTitle("Info")
.setMessage("You are awesome and all answers are correct!")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).setNegativeButton("Cancel", null).show();
}

但是当我尝试将上面的代码放入 UIResponse.java 时

然后像这样调用 QAnswerQuestion.java:

UIResponse.lastQuestionDialog(QAnswerQuestion.this,list);

UIResponse.java代码是

static void lastQuestionDialog(final Context context, List<Question> list)
{
List<Integer> wrongList = UIResponse.checkAnswer(list);
if (wrongList.size() == 0)
{
new AlertDialog.Builder(context).setTitle("Info")
.setMessage("You are awesome and all answers are correct!")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
finish();
}
}).setNegativeButton("Cancel", null).show();
}
}

它说“无法解析完成方法”

最佳答案

问题是您在其他类 UIResponse 中显示对话框。 finish()Activity 的方法。一个简单的解决方案是。

static void lastQuestionDialog(final Context context, List<Question> list)
{
List<Integer> wrongList = UIResponse.checkAnswer(list);
if (wrongList.size() == 0)
{
new AlertDialog.Builder(context).setTitle("Info")
.setMessage("You are awesome and all answers are correct!")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
((Activity)context).finish();
}
}).setNegativeButton("Cancel", null).show();
}
}

除此之外,我建议您使用回调接口(interface)通知 Activity 对话框操作,以便您可以在 Activity 中管理它们。阅读how-to-define-callbacks-in-android .

关于java - 无法解析完成方法——从 Android Studio 方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49456949/

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