/ 我试图在检查时禁用并启用按钮而不是......但是在OnCheckedChangedListener()中显示Class'从OnCheckedChangedListener派生的匿名类'必须被声明为abstract或实现抽象方法'onCheckedChanged( 'OnCheckedChangeLisner'中的CompoundButton,bolean)' /
package com.example.amby.mobihut;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import static android.R.attr.start;
public class SignInScreen extends AppCompatActivity {
AsyncResponse delegate;
Button btn;
CheckBox checkBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in_screen);
//context = this;
//final Context context = this;
btn = (Button) findViewById(R.id.btn_signup);
btn.setEnabled(false);
checkBox = (CheckBox) findViewById(R.id.checkBox);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void OnCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked)
{
btn.setEnabled(true);
}
else
{
btn.setEnabled(false);
}
}
}
);
}
//public void processFinish(String output){}
}
答案 0 :(得分:0)
尝试使用setOnClickListener
CheckBox checkBox = (CheckBox) findViewById (R.id.yourId);
checkBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//is chkIos checked?
if (((CheckBox) v).isChecked()) {
//Case 1
}
else
//case 2
}
});
答案 1 :(得分:0)
您需要覆盖onCheckedChangeListener。在 public void onCheckedChanged(..)之上添加@Override。在这方面:
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
}
});