"变量在内部类中被访问需要声明为最终"是我一开始得到的错误。所以我把它改成final。一旦我将其更改为 final,我就会收到一个不同的错误,说"无法将值分配给最终变量"。我有点被困在这里,不知道该怎么做。它给了我关于int的错误exam_grade
public class CalculateGradeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calculate_grade_view);
seekbar();
}
public void seekbar(){
SeekBar seek_bar1 = (SeekBar) findViewById(R.id.seekBarExam);
final TextView text_view = (TextView) findViewById(R.id.percentageSeekbar1);
int exam_grade;
TextView text_view5 = (TextView) findViewById(R.id.numeric_grade_id_output);
text_view5.setText(String.valueOf(exam_grade));
int progress = seek_bar1.getProgress();
text_view.setText(String.valueOf(progress));
seek_bar1.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
exam_grade = progress;
text_view.setText(String.valueOf(progress) + "%");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
);
}//ends seekbar function
}
嗨,
不要将您的文本视图声明为 final,而是将其放在类属性中。
public class CalculateGradeActivity extends Activity {
TextView text_view;
SeekBar seek_bar1
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calculate_grade_view);
seek_bar1 = (SeekBar) findViewById(R.id.seekBarExam);
text_view = (TextView) findViewById(R.id.percentageSeekbar1);
seekbar();
}
对所有视图执行相同的操作(将它们声明为属性)。
final意味着
它只能分配一次。我确信文本视图不应该是最终的。无论如何尝试将考试成绩和文本视图的声明放在您的创建...
setContentView(R.layout.calculate_grade_view);
int exam_grade;
TextView text_view = (TextView) findViewById(R.id.percentageSeekbar1);
seekbar();