我想比较一个EditText值和一个共享首选项,但即使它们是相同的,它也不起作用,它们是我的代码:
public void random_question_answer(){
final int rando = (int) (Math.random() * arr_question.length);
final EditText answer = (EditText) findViewById(R.id.answer);
final String thequestion = prefA.getString(arr_question[rando],"");
final String theanswer = answer.getText().toString();
final boolean com = theanswer.trim().equalsIgnoreCase(thequestion.trim().toString());
question.setText(arr_question[rando]);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(com == true){
situation1.setVisibility(View.VISIBLE);
}else{
situation2.setText(thequestion+"/"+theanswer);
situation2.setVisibility(View.VISIBLE);
}
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
situation1.setVisibility(View.GONE);
situation2.setVisibility(View.GONE);
situation2.setText("Wrong!");
answer.setText("");
random_question_answer();
}
},
2000);
}
});
}