对于所有我正在使用 android 并希望RadioGroup
在CheckBox
简单的应用程序中同时使用的人,我想同时使用setOnCheckedChangeListener()
这两种方法,但我遇到错误说导入冲突。我的代码是:
public class MainActivity extends Activity {
RadioGroup radioGroup;
CheckBox checkBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
checkBox = (CheckBox) findViewById(R.id.checkBox1);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
int option = radioGroup.getCheckedRadioButtonId();
if(option == R.id.radio0){
Toast.makeText(MainActivity.this, "You Selected Java is Best", Toast.LENGTH_LONG).show();
}
else if(option == R.id.radio1){
Toast.makeText(MainActivity.this, "You Selected C++ is Best", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(MainActivity.this, "You Selected C# is Best", Toast.LENGTH_LONG).show();
}
}
});
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
Toast.makeText(MainActivity.this, "You Selected Yes", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MainActivity.this, "You Un-selected Yes", Toast.LENGTH_LONG).show();
}
}
});
}
Edit
我的进口是:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;// this one collides with
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;// this one
现在我无法解决这个问题,请告诉我该怎么做。提前致谢...