views:

60

answers:

2

Hello,

On my application I'm developing, the main.xml layout (the default layout of my app) has a few buttons that have been assigned onClickListeners (not the implementation way).

One of those buttons I want to have the ability to take you to another view. On the other view (preview.xml), there's another button that takes you back to the main.xml view.

I've used setContentView in the onClickListeners of those buttons and this works fine so far, but after you click the button that takes you back to main.xml, the buttons on main.xml have lost their onClick functionalities.

How can I get this to work right? I presume using setContentView isn't the right way to do this?

Thanks for reading.

A: 

I'd say use two different activities and switch between them. Another option can be ViewSwitcher http://developer.android.com/intl/zh-TW/reference/android/widget/ViewSwitcher.html

Konstantin Burov
A: 

Your best bet, at Konstantin says above is to use Activities, as you will come across these a lot whilst developing for android. you can read about them here Activities. I assume you want to pass something onto the preview.xml page? If so, I'd recommend either putting it as an extra in the Intent used to start the activity (see the link) or creating a static reference in the activity (which you set before you launch it).

Espiandev