Android页面Activity还是Layout?

发布于 2024-09-26 07:58:16 字数 208 浏览 1 评论 0原文

我的应用程序由一个带有“开始”、“关于”等的介绍页面组成。

我通过让“开始”按钮调用一个定义了新的 onclick 侦听器的新布局,成功创建了该应用程序的功能版本。

这对我来说似乎不太清楚,我正在为我使用的每个布局定义一个新的 onClick 侦听器,并且想知道创建单独页面(包括我的“关于”和我实现的任何其他屏幕)的正确方法。

任何建议表示赞赏,谢谢。

My app Consists an intro page with "Start", "About", etc..

I managed to create a functional version of the app by having the "Start" button call a new layout in which a new onclick listener is defined.

This doesn't seem clean to me that I@m defining a new onClick listener for each Layout I use and wonder how the correct way would be to create individual pages (including my "About" and any other screens I implement).

Any advice is appreciated, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-10-03 07:58:16

您应该为每个“屏幕”创建一个活动。所有按钮都将启动相同的事件 (onClick),并且您将查看事件源视图的 ID 来启动正确的活动。
像这样的事情:

public void onButtonClick(View target) {
       System.out.println("Button clicked '" + target + "'");

       switch (target.getId()) {
            case R.id.a_button:
                Intent intent = new Intent(this, AboutActivity.class);
                this.startActivity(intent);
            break;
       }
}

You should create an Activity for each "screen". All the buttons will launch the same event (onClick) and you will start the right activity looking at the ID of the event's source view.
Something like this:

public void onButtonClick(View target) {
       System.out.println("Button clicked '" + target + "'");

       switch (target.getId()) {
            case R.id.a_button:
                Intent intent = new Intent(this, AboutActivity.class);
                this.startActivity(intent);
            break;
       }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文