我使用这个库来构建对话框:https://github.com/afollestad/material-dialogs/
我收到这个提示
Anonymous new MaterialDialog.SingleButtonCallback() can be replaced with lambda hint.
自从更新到 Android Studio 2.4 prev 4 以来,它向我显示了这个问题:
这是代码:
public void swapConfirm() {
MaterialDialog dialog = new MaterialDialog.Builder(this)
.title(R.string.swap_teams)
.content(R.string.swap_confirm)
.positiveText(R.string.swap_teams)
.negativeText(android.R.string.cancel)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
swapTeams("");
}
}).build();
dialog.show();
}
如何将其更改为新的 lambda 架构?
我根据this blog post尝试了以下操作,但它不起作用:
最佳答案
由于错误表明变量 dialog
已在范围内定义,因此将其名称更改为 dialog1
之类的名称,例如,它应该可以工作。
如果您通过单击 Alt+Enter
并从 Intent 列表中选择第一个选项,让 Android Studio 将匿名类转换为 lambda,则不会发生此错误。
关于android - 匿名类可以用lambda提示替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43252735/