문제

I'm very new on Android development.

I have this:

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();

But this line doesn't work:

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

I can't get access to this.gameId.

How can I fix this?

Thanks.

도움이 되었습니까?

해결책

Because you are using an anonymous inner class the "this" actually refers to that class. You can refer to your main class's private fields either by removing the "this." or writing: "NameOfYourMainClass.this.gameId"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top