the tutorial i am learning of of is from the late 2000s is there a new way or something have i done something wrong please help

this is my first post yaaah

sorry if this isnt allowed in this section of the forum i see that people are asking question here aswell but when i go to post this threads it says that you cant post it here

any way thxs for ur help in advance

It is the right way to do it, only you messed up the names. If you have two Buttons in your layout (yes and no), you set an onClickListener on one of them calling <buttonName>.setOnClickListener(...);, so in this case yes.setOnClickListener(...). Also I would suggest renaming your Buttons in the code to bYes and bNo or something like that so you know it is a Button. And yes, it is the right section

Dont you also have to declare the buttons withButton yes = (Button)findViewById(R.id.byes);

If you do it this way, "yes" is only declared in the scope of the onCreate method. It is possible, but for views which sit in memory anyway it's more convenient to have the those delared as instance variables like he did above, right below the class declaration.

If you do it this way, "yes" is only declared in the scope of the onCreate method. It is possible, but for views which sit in memory anyway it's more convenient to have the those delared as instance variables like he did above, right below the class declaration.

Dont you also have to declare the buttons withButton yes = (Button)findViewById(R.id.byes);

You don't have to cast to Button class in this particular case, View has already defined method "setOnClickListener".
And yes, you better declare field to keep reference and avoid additional findViewById() calls.

XDA Developers was founded by developers, for developers. It is now a valuable resource for people who want to make the most of their mobile devices, from customizing the look and feel to adding new functionality.Are you a developer?