如何使用Android中按钮来打开新的Andr​​oid XML页面? [英] How to open new android XML page with button in Android?

查看:170
本文介绍了如何使用Android中按钮来打开新的Andr​​oid XML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要有打开新的 XML 页用户查看按钮的应用程序。我是新来的这一点,从小事我发现了,我想我需要这样的事,但我不知道,可能是错误的:

I want to make a app that has buttons that open new XML pages for the user to view. I'm new to this and from the little I found, I think I need something like this but I'm not sure and could be wrong:

Button myButton = (Button) findViewById(R.id.my_button);

setContentView(R.layout.page1);

但我不知道进口的,也如果任何人对我可以遵循,以了解更多有关编码的Andr​​oid应用程序很好的教程知道了。

But I'm not sure of the imports and also if anyone knows on good tutorials that I could follow to learn more on coding Android apps.

推荐答案

在下面添加code在主actiivty

Add below code in your main actiivty

Button button = (Button) findViewById(R.id.button);
button.setOnClickListener (new View.OnClickListener() {
    public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(),NewActivity.class);
        startActivity(i);
    }
});

创建一个新的活动名称NewActivity.java
 在其onCreate方法通过下列语句添加你想要的XML。

Create a new activity name NewActivity.java in its onCreate method add the xml you want by using below statement.

setContentView(R.layout.page1);

这篇关于如何使用Android中按钮来打开新的Andr​​oid XML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆