gpt4 book ai didi

java - 更改局部变量 android onClickListener

转载 作者:行者123 更新时间:2023-11-30 03:26:13 25 4
gpt4 key购买 nike

我需要将此方法的返回值设置为在单选对话框中选择的项目...

但是,我无法设置 retVal 的值,因为它显然需要是最终值(因此无法更改)

有没有不用全局变量的方法呢?

private String getSaleType()
{
String retVal = "";
final String[] TYPES = {"Cash Sale", "Sales Order"};
AlertDialog.Builder choose = null;

try
{
choose = new AlertDialog.Builder(this);
choose.setIcon(R.drawable.firstdroidicon);
choose.setTitle("Sale Type");
choose.setMessage("Type Of Sale?");
choose.setSingleChoiceItems(TYPES, currentItem, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Log.i("Selected", TYPES[which]);
}
});
choose.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
retVal = TYPES[which];
}
});

}
catch(Exception e)
{
messageBox("getSaleType", e.getMessage());
}

return retVal;
}

最佳答案

不可能。

您可以在 JLS # chapter 8 中找到它

Any local variable, formal parameter, or exception parameter used but not declared in an inner class must be declared final.

Any local variable used but not declared in an inner class must be definitely assigned (§16) before the body of the inner class.

关于java - 更改局部变量 android onClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18207182/

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