【发布时间】:2015-02-27 14:49:39
【问题描述】:
我的应用程序中有一个使用条款部分,我想在用户选中复选框时激活一个按钮。
【问题讨论】:
-
如果您的复选框已选中,则启用按钮,否则禁用 it.set 按钮在 Main 类的 oncreate() 方法上的侦听器。 Android Studio 与它无关。
标签: android button checkbox android-studio
我的应用程序中有一个使用条款部分,我想在用户选中复选框时激活一个按钮。
【问题讨论】:
标签: android button checkbox android-studio
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.content_layout_id);
final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
final Button b = (Button)findViewById(R.id.button_id)
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (buttonView.isChecked()) {
b.setEnabled(true);
} else {
b.setEnabled(false)
}
}
});
}
}
【讨论】: