Question

Je suis très nouveau sur le développement Android.

J'ai ceci:

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

Mais cette ligne ne fonctionne pas:

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

Je ne peux pas avoir accès à this.gameId.

Comment puis-je résoudre ce problème?

Merci.

Était-ce utile?

La solution

Parce que vous utilisez une classe interne anonyme de « ce » fait référence à cette classe. Vous pouvez vous référer aux champs privés de votre classe principale, soit en supprimant le « cela. » ou en écrivant: "NameOfYourMainClass.this.gameId"

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top