0

私はAndroid開発に関して非常に新しいです。

私はこれを持っています:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.message_user_registered)
       .setCancelable(false)
       .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               Intent intent = 
                   new Intent(GameDescriptionActivity.this,
                              GameHomeActivity.class);

               Bundle extraData = new Bundle();
               extraData.putInt(Constants.GAME_ID, this.gameId);

               startActivity(intent);
           }
       });
AlertDialog alert = builder.create();
alert.show();

しかし、この行は機能しません:

extraData.putInt(Constants.GAME_ID, this.gameId);

にアクセスできませんthis.gameId

どうすればこれを修正できますか?

ありがとう。

4

1 に答える 1

3

匿名の内部クラスを使用しているため、「これ」は実際にはそのクラスを参照しています。「this」を削除することで、メイン クラスのプライベート フィールドを参照できます。または書き込み: "NameOfYourMainClass.this.gameId"

于 2010-10-12T15:51:11.210 に答える