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

How do I copy and past text view element?

This question is in refenece to adding a button element to an Android app.

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Are you looking to add a second TextView? Or since you mention a Button, are you looking to copy the TextView and change it to a Button?

To just copy and paste, you can right-click on elements in the Design view and copy and paste them, or use keyboard shortcuts like Ctrl+C/Ctrl+V (Cmd+C/Cmd+V for Mac). You can also switch to the Text tab (XML view) and copy the XML text for a TextView from there.

If you need a Button, it'll be better to just drag a new one in from the Palette.

If you're talking about where the views are accessed in the Activity, then you will want to declare a Button variable and set it using findViewById() just like the code for a TextView.