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 trial

Android Build a Simple Android App Basic Android Programming Making a Button Do Something

Why not use the onclick from the properties tab in your activity main and link the button with a function ?

What is the difference between using this method of onclick or using the properties from the activity main xml file.

I usually link the button with a function like:

public void OnClick(View view) { do something }

1 Answer

Micheal Ammirati
Micheal Ammirati
5,377 Points

Sometimes there are a few ways to accomplish the same thing in android studio. I like to design the layout first, then do all of the interaction implementation later in the code. It is easy to just add onclicks in the layout design view for small projects, but as you build more complex layouts and activities you should probably think about keeping your design time and coding time separated to keep your sanity.