开发者

How to go to the next layout after button click on main.xml and go to the next layout again in android

hi i would like to know how to i go to the next layout on android. i am new to designing apps and i managed to have main.xml with a button that has onclicklistener and r.layout.second.xml, that is done. now when i am at second.xml, i want to go to third.xml, however, when i click the button on the third.xml, it does nothing.

i have added a new ac开发者_开发知识库tivity.java with roughly the same code as the main.java file with exception that setContentView(R.layout.second);

i have added new activity to manifest however, when i reach the second.xml, i cannot click to third.xml.

any help please.


Layouts as you refer to them are tied to Activities (you can tie several layouts to a single activity by using ViewFlipper though).

What you're looking for is not to go to the second layout, but rather to move to the next activity.

You might have a button, where onClick executes the code to move to the next activity.

You'll need to use Intents to start a new activity, e.g.:

Intent nextActivity = new Intent(this, SecondActivity.class);
startActivity(nextActivity);

This will start the new activity, and by extension, use the second layout you're after.

As a test run, if you don't want to add a button yet, you could use the above code in your onCreate method, though it'll appear as though it's opened the second activity immediately. In reality, it'll open the first, and start the second before you can see it; you can press back on your device to show that the first activity was, in fact, created.

HTH

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜