[英]How to get radiobutton value?
Here is my code 这是我的代码
//unlock
rbtnUTrue = new RadioButton("rbtnUnlock", "True");
rbtnUFalse = new RadioButton("rbtnUnlock", "False");
hp = new HorizontalPanel();
hp.add(rbtnUTrue);
hp.add(rbtnUFalse);
vlc.add(new FieldLabel(hp, "Has Unlock"), new VerticalLayoutData(1, -1, new Margins(10)));
if (rbtnUTrue.isChecked()) {
dummy_u = 1;
} else if (rbtnUFalse.isChecked()) {
dummy_u = 0;
}
but it always says that I clicked the false button 但总是说我点击了假按钮
To answer your question: "how to get data from radio buttons in gwt?": 要回答您的问题:“如何从gwt中的单选按钮获取数据?”:
radioButton.getValue();
or radioButton.isChecked();
或radioButton.isChecked();
I'm not sure what do you want to achieve with the if-clause. 我不确定if子句要实现什么。 If you need an initial value then just set it. 如果您需要初始值,则只需进行设置即可。
What you probably want to do is to register when the button is clicked: 您可能想要做的是在单击按钮时进行注册:
rbtnUTrue.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (rbtnUTrue.isChecked()) {
dummy_u = 1;
} else if (rbtnUFalse.isChecked()) {
dummy_u = 0;
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.