我想定義一個TextView最終變量但是說:不能賦值給最終變量。不能賦值給最終變量 - Android
在下面的代碼中,我插入了一些評論,以幫助捕捉更容易的問題。
任何幫助?
在此先感謝!
CODE:
public class single_presentation extends Activity
{
List<Slider> list;
final TextView correctAnswerHolder = null;
int i = 0;
DatabaseHelper db = new DatabaseHelper(this);
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.single_presentation);
String value = getIntent().getStringExtra("PRESENTATION_SESSION_ID");
list = db.getAllSlidersByPresentation(value);
db.close();
String question = list.get(0).getQuestion();
TextView questionText = (TextView) findViewById(R.id.questionText);
questionText.setText(question);
String correctAnswer = list.get(0).getCorrectAnswer();
TextView correctAnswerText = (TextView) findViewById(R.id.correctAnswerText);
String wrongAnswer_1 = list.get(0).getWrongAnswer1();
TextView wrongAnswerText_1 = (TextView) findViewById(R.id.wrongAnswerText_1);
String wrongAnswer_2 = list.get(0).getWrongAnswer2();
TextView wrongAnswerText_2 = (TextView) findViewById(R.id.wrongAnswerText_2);
String wrongAnswer_3 = list.get(0).getWrongAnswer3();
TextView wrongAnswerText_3 = (TextView) findViewById(R.id.wrongAnswerText_3);
Uri imgUri = list.get(i).getImageURI();
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageURI(imgUri);
final String [] answers = {correctAnswer, wrongAnswer_1, wrongAnswer_2, wrongAnswer_3};
ArrayList<String> answersList = new ArrayList<String>(Arrays.asList(answers));
long seed = System.nanoTime();
Collections.shuffle(answersList, new Random(seed));
Log.e("First Slider Answers ", answersList.toString());
correctAnswerText.setText(answersList.get(0));
wrongAnswerText_1.setText(answersList.get(1));
wrongAnswerText_2.setText(answersList.get(2));
wrongAnswerText_3.setText(answersList.get(3));
if (correctAnswerText.getText().toString().equals(correctAnswer))
correctAnswerHolder = correctAnswerText; // HERE is the problem
else if (wrongAnswerText_1.getText().toString().equals(correctAnswer))
correctAnswerHolder = wrongAnswerText_1; // HERE is the problem
else if (wrongAnswerText_2.getText().toString().equals(correctAnswer))
correctAnswerHolder = wrongAnswerText_2; // HERE is the problem
else if (wrongAnswerText_3.getText().toString().equals(correctAnswer))
correctAnswerHolder = wrongAnswerText_3; // HERE is the problem
是的,你不能,爲什麼你要聲明,作爲'最後'? –
你真的知道'Java'嗎?你需要閱讀Java編程書! –
我想在correctAnswerHolder.setOnClickListener中使用它以獲取correctAnswerHolder的更改。 – Joan