[英]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.