单击图像按钮

发布于 2024-11-16 11:49:23 字数 111 浏览 5 评论 0原文

我有一个问题。

有 4 个图像按钮(a1、a2 和 b1、b2)。您只能选择 a1 或 a2,不能同时选择两者。我应该检查这些按钮的每次点击吗?

我该怎么做?有人可以帮助我吗?

I have one question.

There are 4 ImageButtons(a1, a2 and b1, b2). You can chose only a1 or a2 and never both at the same time. Should I check each click on these buttons?

How can I do this? Can anyone help me?

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

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

发布评论

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

评论(1

风柔一江水 2024-11-23 11:49:23

有一种简单的方法可以做到这一点:

当您单击一个按钮时,将其他按钮的启用设置为 false 并反对。

代码:

b1.setOnTouchListener(new OnTouchListener(){
   public void onTouch(View v, MotionEvent event){
      if(event.getAction() == MotionEvent.ACTION_DOWN)b2.setEnabled(false);
      else if(event.getAction() == MotionEvent.ACTION_UP)b2.setEnabled(true);
   }
});

b2.setOnTouchListener(new OnTouchListener(){
   public void onTouch(View v, MotionEvent event){
      if(event.getAction() == MotionEvent.ACTION_DOWN)b1.setEnabled(false);
      else if(event.getAction() == MotionEvent.ACTION_UP)b1.setEnabled(true);
   }
});

There is one easy way to do this:

when you click one button set enablet to false to other button and against.

Code:

b1.setOnTouchListener(new OnTouchListener(){
   public void onTouch(View v, MotionEvent event){
      if(event.getAction() == MotionEvent.ACTION_DOWN)b2.setEnabled(false);
      else if(event.getAction() == MotionEvent.ACTION_UP)b2.setEnabled(true);
   }
});

b2.setOnTouchListener(new OnTouchListener(){
   public void onTouch(View v, MotionEvent event){
      if(event.getAction() == MotionEvent.ACTION_DOWN)b1.setEnabled(false);
      else if(event.getAction() == MotionEvent.ACTION_UP)b1.setEnabled(true);
   }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文