1

このメソッドの戻り値を、単一選択ダイアログで選択された項目に設定する必要があります...

ただし、明らかに最終的な必要があるため、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;
}
4

1 に答える 1

1

ありえない。

JLS#第8章でそれを見つけることができます

使用されているが内部クラスで宣言されていないローカル変数、仮パラメーター、または例外パラメーターは、final として宣言する必要があります。

内部クラスで使用されているが宣言されていないローカル変数は、内部クラスの本体の前に確実に割り当てる必要があります (§16)。

于 2013-08-13T11:04:02.873 に答える