改变活动

发布于 2025-01-06 00:58:55 字数 110 浏览 3 评论 0原文

如果我有 5 个(或更多按钮),当所有按钮都被按下时,是否可以更改活动。就像按下最后一个按钮时一样,我的应用程序应该更改活动。最后按下这五个按钮中的哪一个按钮并不重要。

有什么想法吗? :)

Is it possible if I have 5 (or more buttons) to change activity when all of then are pressed. Like when last button is pressed my app should change activity. And it shouldn't matter what button of those five is pressed last.

Any ideas? :)

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

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

发布评论

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

评论(1

暮年慕年 2025-01-13 00:58:55

当然,为每个按钮创建一个布尔值数组:

boolean[] pressedButtons = new boolean[5];

在每个侦听器中,按下按钮时将数组中相应的单元格设置为 true,然后调用这样的方法(抽象实现):

private void startActivityIfReady() {
    boolean ready = true;
    for (boolean b : pressedButtons)
        ready = ready && b;
    if (ready) {
        // start your activity
    }
}

Sure, create an array of booleans for each button:

boolean[] pressedButtons = new boolean[5];

In each of the listeners, when the button is pressed set the appropriate cell in the array to true, and then call such a method (abstract implementation):

private void startActivityIfReady() {
    boolean ready = true;
    for (boolean b : pressedButtons)
        ready = ready && b;
    if (ready) {
        // start your activity
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文