简体   繁体   English

如何检查是否在Java中的其他类中单击了按钮?

[英]How to check if a button was clicked in a different class in java?

I have 4 button in 1 (Class A) of my classes. 我的班级1(班级A)中有4个按钮。 All buttons lead to the same class (Class B), however, I want to set an if restriction depending on what button is clicked in Class A. Here is a sample of my code. 所有按钮都导致同一个类(B类),但是,我想根据是否在A类中单击哪个按钮来设置if限制。这是我的代码示例。

I want to change the value of qid depending on what option is clicked. 我想根据单击的选项来更改qid的值。 For example, if the clicked was 5, the if statement should be "qid > 5". 例如,如果单击的值为5,则if语句应为“ qid> 5”。 If button clicked was 10, the if statement should be "qid > 10". 如果单击的按钮为10,则if语句应为“ qid> 10”。 I am not sure if you can do this, but I think if we assign a number to each button that gets transferred to Class B, the the If statements could become "If (code=1 || qid > 5). Again, I'm not certain how to approach this. Any help would be appreciated. Thanks in Advance. 我不确定您是否可以执行此操作,但是我认为,如果我们为要转移到B类的每个按钮分配一个数字,则If语句可能变为“ If(code = 1 || qid> 5)。再次,我不确定该如何处理。我们将不胜感激。在此先感谢您。

Send: 发送:

Intent i = new Intent(this, ToClass.class);
i.putExtra("button", "5");
startActivity(i);

Receive: 接收:

Intent intent = getIntent();
int buttonValue = Integer.valueOf(intent.getExtras().getString("button"));
if (qid > buttonValue ) {
    // Do stuff...
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM