我需要将此方法的返回值设置为在单选对话框中选择的项目...
但是,我无法设置 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;
}