Java Android RadioButton CompoundButton.OnCheckedChangeListener错误
我对我的代码有一个问题,它应该更改我开始活动的背景色。我应该用单选按钮(在Radiogroup中)在蓝色和红色之间进行选择。我总是会遇到这样的错误: 错误:(8,8)错误:com.example.clecks.reaction\u game.oncheckedchangedListener不是抽象的,并且不会覆盖android.widget.CompoundButton.oncheckedchangedListener中的抽象方法onCheckedChanged(CompoundButton,布尔值) C:\Users\clecks\Desktop\asdfasdf\app\src\main\java\com\example\clecks\reaction\u game\OnCheckedChangeListener.java 当我单击错误消息时,会打开一个名为Java Android RadioButton CompoundButton.OnCheckedChangeListener错误,java,android,colors,Java,Android,Colors,我对我的代码有一个问题,它应该更改我开始活动的背景色。我应该用单选按钮(在Radiogroup中)在蓝色和红色之间进行选择。我总是会遇到这样的错误: 错误:(8,8)错误:com.example.clecks.reaction\u game.oncheckedchangedListener不是抽象的,并且不会覆盖android.widget.CompoundButton.oncheckedchangedListener中的抽象方法onCheckedChanged(CompoundButton,布
OnCheckedChangeListener.java
:
public class OnCheckedChangeListener implements CompoundButton.OnCheckedChangeListener {}
这是我的密码:
public class activity_settings extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_settings);
colorchange();
}
public void colorchange() {
final RelativeLayout background = (RelativeLayout) findViewById(R.id.start);
final RadioButton changeToBlue = (RadioButton) findViewById(R.id.button_blue);
final RadioButton changeToRed = (RadioButton) findViewById(R.id.button_red);
final Button button_save = (Button) findViewById(R.id.button_save);
button_save.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
changeOption(background);
}
});
changeToBlue.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
changeToBlue(background);
}
});
changeToRed.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
changeToRed(background);
}
});
}
public void changeOption(RelativeLayout background) {
if (background.isEnabled()) {
background.setEnabled(false);
} else {
background.setEnabled(true);
}
}
public void changeToBlue(RelativeLayout background) {
background.setBackgroundColor(0x0000FF00);
background.invalidate();
}
public void changeToRed(RelativeLayout background) {
background.setBackgroundColor(0x0000FF00);
background.invalidate();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_activity_settings, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}}
它本身是一个抽象类(扩展`Button)
在“活动\u活动\u设置”布局中,不应该有CompoundButton
例如,使用
按钮
。我的布局中没有任何复合按钮-它们都是RadioButton,因此不要在代码中使用复合按钮
,而是使用RadioButtons
。为什么使用了错误的类型?我有,但与(我站在Oo行上)相同的错误:changeToBlue.setOnCheckedChangeListener(新RadioButton.OnCheckedChangeListener(){@Override public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){changeToBlue(后台);} });请更新您的问题。错误消息不能完全相同,因为您更改了类…错误:(8,8)错误:com.example.clecks.reaction\u game.oncheckedchangedListener不是抽象的,并且不会重写onCheckedChanged(CompoundButton,布尔值)的抽象方法在android.widget.CompoundButton.OnCheckedChangeListener C:\Users\clecks\Desktop\asdfasdf\app\src\main\java\com\example\clecks\reaction\u game\OnCheckedChangeListener.java中,为什么错误会抱怨com.example.clecks.reaction\u game.OnCheckedChangeListener
?这是怎么一回事?在这种情况下,什么是activity\u settings
?activity\u settings是我在游戏设置菜单中的活动,在这里我可以选择背景和声音。嗯……我不知道,我删除了com.example.clecks.reaction\u game.OnCheckedChangeListener,现在我可以运行它了,但是有一个新的错误,我会更新……意味着你在另一个类com.example.clecks.reaction\u game.OnCheckedChangeListener
中遇到了我帮助你修复的错误。现在,活动设置
已修复。