开发者

Android Development: Switching between Views without losing onClickListeners

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 th开发者_JAVA百科e 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.


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).


I'd say use two different activities and switch between them. Another option can be ViewSwitcher.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜