Ash*_*ing 0 java android radio-group radio-button
我在 setOnCheckedChangeListener 和 OnCheckedChangeListener 下有红线。错误消息告诉我:此行有多个标记 - OnCheckedChangedListener 无法解析为类型 - RadioGroup 类型中的方法 setOnCheckedChangedListener(RadioGroup.OnCheckedChangeListener) 不适用于参数 (new OnCheckedChangeListener(){})
package com.lifematters;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class Test1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test1);
//define Navigation Image Buttons
final Button nextBtn = (Button) findViewById(R.id.btnNext);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioAnswers1);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged (RadioGroup group, int checkedId){
final RadioButton radioButton1 = (RadioButton) findViewById(R.id.radioA1);
final RadioButton radioButton2 = (RadioButton) findViewById(R.id.radioA2);
final RadioButton radioButton3 = (RadioButton) findViewById(R.id.radioA3);
final RadioButton radioButton4 = (RadioButton) findViewById(R.id.radioA4);
if (radioButton1.isChecked()) {
DisplayToast("No, not at all");
} else if (radioButton2.isChecked()) {
DisplayToast("On some days");
}else if (radioButton3.isChecked()) {
DisplayToast("On more than half the days");
}else {
DisplayToast("Nearly everyday");
}
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
两种可能性:
改成RadioGroup.OnCheckedChangeListener
将其添加到课程的开头:
import android.widget.RadioGroup.OnCheckedChangeListener;
Run Code Online (Sandbox Code Playgroud)对于DisplayToast,添加以下内容:
public void displayToast(String text){
Toast.makeText(this, text, Toast.Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
并在您的代码中更改DisplayToast为。displayToast按照惯例,方法名称应以小写字母开头。只有类名应该以大写字母开头。
| 归档时间: |
|
| 查看次数: |
5048 次 |
| 最近记录: |