简体   繁体   English

如何检查用户何时单击了正确的按钮?

[英]How do I check when a user clicks the correct button?

So, I am pretty new to programming, and even newer to Android Studio and Java, and i've been struggling with this one...所以,我对编程很陌生,甚至对 Android Studio 和 Java 也很陌生,我一直在努力解决这个问题......

So, in my activity i have 9 buttons, each with their own colour.所以,在我的活动中,我有 9 个按钮,每个按钮都有自己的颜色。 When the user clicks the 'start' button, the name of one of the colours is randomly chosen and appears (Did this with an array).当用户点击“开始”按钮时,其中一种颜色的名称会被随机选择并出现(用数组做这件事)。 Then the user has to click the button with the correct colour.然后用户必须单击具有正确颜色的按钮。

The thing I'm having trouble with is checking whether and when the user has clicked the right button.我遇到的问题是检查用户是否以及何时单击了正确的按钮。 Any help with how to go about this would be much appreciated!任何有关如何解决此问题的帮助将不胜感激!

Check which button was clicked and then check if the clicked button has the right color:检查单击了哪个按钮,然后检查单击的按钮是否具有正确的颜色:

ColorDrawable buttonColor = (ColorDrawable) button.getBackground();
int colorValue = buttonColor.getColor();
if(colorValue==rightColor){...}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户单击X按钮退出程序时,如何编写一个弹出对话框的编码? - How do I code a pop up dialog box to appear when the user clicks the X button to exit the program? 用户单击按钮时如何更改计时器的关键帧持续时间? - How do I change the KeyFrame duration of my timer when user clicks a button? 当用户单击GUI中的按钮时,我想打开一个图像 - I would like to open an image when a user clicks on a button in GUI 当用户尝试关闭窗口按钮时,如何检查文件是否已保存? - How do I check if a file is saved when the user tries to close the window button? 用户单击webView上的“提交”按钮时如何完成活动 - How to finish the activity when user clicks on the submit button on webView 在swing GUI中,如何在用户单击按钮时将JPanel显示为最大化? - In swing GUI how to show a JPanel as maximized when the user clicks a button? 当用户单击取消时,如何使用 JOptionPane 从子菜单返回主菜单? - How do I go back to the main menu from a sub menu using JOptionPane when the user clicks cancel? 用户单击红叉时如何显示确认消息? Java GUI - How do i display a confirmation message when the user clicks on the red cross? Java GUI 用户单击主页按钮时终止活动 - Killing the activity when user clicks the home button 当用户注销后单击“后退”按钮时,会话如何失效,例如银行网站 - How to session expire when user clicks back button after log out i.e. like bank website
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM