Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGeorgi Kamoyan
Courses Plus Student 3,009 PointsHow do we show in code, that the onClickListener is applied exactly to the "Show Another Fact" button.
This is a general question.
We set a listener = View.onClickListener. How do we understand, that this is a listener of "Show another fact" button. How we could link the listener to another button, if another button exists on the layout.
2 Answers
Ricky Catron
13,023 PointsWhat I usually do is:
ButtonNameHere.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Action the button will perform here
}
});
If you need another button simply repeat the code with a different buttonName.
Goodluck! --Ricky
Georgi Kamoyan
Courses Plus Student 3,009 PointsThanks Ricky!
Ricky Catron
13,023 PointsGlad to help!