我有一些按钮,我从导入和预先填充的sqlite数据库中为其中一些设置了一些文本。这很好。现在我有几个按钮打开警报对话框供用户输入解决方案,然后我将其与我数据库中的正确解决方案进行比较。对于columnA,R.id.bKolonaA在我的代码中,它工作正常,它向我显示“正确答案”文本的吐司。但是在columnB上,每当我输入解决方案时,我都会得到“错误的答案”吐司,即使我知道它是正确的。我确保在这些方法中使用的所有变量都是不同的。下面你可以看到我的一些课程,重要的部分,它是相当大的课程,所以我在这里粘贴了一些重要的部分。 任何人都可以看到错误在哪里?
public class Asocijacije extends Activity implements OnClickListener{
final Context context = this;
Editable ukucanRezultatA, ukucanRezultatB, ukucanRezultatC, ukucanRezultatD, ukucanRezultatK;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.asocijacije);
nextQuestion();
}
private void nextQuestion() {
TestAdapter mDbHelper = new TestAdapter(this);
mDbHelper.createDatabase();
try{
mDbHelper.open();
Cursor c = mDbHelper.getAsocijacije(generateWhereClause());
mAnsweredQuestions.add(c.getLong(0));
mA1 = c.getString(6);
mA2 = c.getString(7);
mA3 = c.getString(8);
mA4 = c.getString(9);
mB1 = c.getString(10);
mB2 = c.getString(11);
mB3 = c.getString(12);
mB4 = c.getString(13);
mC1 = c.getString(14);
mC2 = c.getString(15);
mC3 = c.getString(16);
mC4 = c.getString(17);
mD1 = c.getString(18);
mD2 = c.getString(19);
mD3 = c.getString(20);
mD4 = c.getString(21);
mAKolonaA = c.getString(2);
mBKolonaB = c.getString(3);
mCKolonaC = c.getString(4);
mDKolonaD = c.getString(5);
mKonacno = c.getString(1).toUpperCase();
konacanNormalized = Normalizer.normalize(mKonacno, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").toUpperCase();
kolonaANormalized = Normalizer.normalize(mAKolonaA, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").toUpperCase();
kolonaBNormalized = Normalizer.normalize(mBKolonaB, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").toUpperCase();
kolonaBNormalized = Normalizer.normalize(mCKolonaC, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").toUpperCase();
kolonaBNormalized = Normalizer.normalize(mDKolonaD, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").toUpperCase();
a1.setOnClickListener(this);
a2.setOnClickListener(this);
a3.setOnClickListener(this);
a4.setOnClickListener(this);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
c1.setOnClickListener(this);
c2.setOnClickListener(this);
c3.setOnClickListener(this);
c4.setOnClickListener(this);
d1.setOnClickListener(this);
d2.setOnClickListener(this);
d3.setOnClickListener(this);
d4.setOnClickListener(this);
kolonaA.setOnClickListener(this);
kolonaB.setOnClickListener(this);
kolonaC.setOnClickListener(this);
kolonaD.setOnClickListener(this);
}
finally{
mDbHelper.close();
}
}
public void onClick(View v) {
switch(v.getId()){
case R.id.bKolonaA:
LayoutInflater layoutInflaterA = LayoutInflater.from(context);
View promptViewA = layoutInflaterA.inflate(R.layout.popup_answer, null);
AlertDialog.Builder alertDialogBuilderA = new AlertDialog.Builder(context);
// set prompts.xml to be the layout file of the alertdialog builder
alertDialogBuilderA.setView(promptViewA);
final EditText inputA = (EditText) promptViewA.findViewById(R.id.userInput);
alertDialogBuilderA
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// get user input and set it to result
ukucanRezultatA = inputA.getText();
String ukucanRezultatStrA = ukucanRezultatA.toString().toUpperCase();
if (ukucanRezultatStrA.equals(kolonaANormalized)){
kolonaA.setText(mAKolonaA);
Toast.makeText(Asocijacije.this, "Correct Answer!!", Toast.LENGTH_SHORT).show();
a1.setText(mA1);
a2.setText(mA2);
a3.setText(mA3);
a4.setText(mA4);
kolonaA.setText(mAKolonaA);
}else{
Toast.makeText(Asocijacije.this, "Wrong answer!", Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create an alert dialog
AlertDialog alertA = alertDialogBuilderA.create();
alertA.show();
break;
case R.id.bKolonaB:
LayoutInflater layoutInflaterB = LayoutInflater.from(context);
View promptViewB = layoutInflaterB.inflate(R.layout.popup_answer, null);
AlertDialog.Builder alertDialogBuilderB = new AlertDialog.Builder(context);
// set prompts.xml to be the layout file of the alertdialog builder
alertDialogBuilderB.setView(promptViewB);
final EditText inputB = (EditText) promptViewB.findViewById(R.id.userInput);
alertDialogBuilderB
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// get user input and set it to result
ukucanRezultatB = inputB.getText();
String ukucanRezultatStrB = ukucanRezultatB.toString().toUpperCase();
if (ukucanRezultatStrB.equals(kolonaBNormalized)){
kolonaB.setText(mBKolonaB);
Toast.makeText(Asocijacije.this, "Correct answer!!", Toast.LENGTH_SHORT).show();
b1.setText(mB1);
b2.setText(mB2);
b3.setText(mB3);
b4.setText(mB4);
kolonaB.setText(mBKolonaB);
}else{
Toast.makeText(Asocijacije.this, "Wrong answer!", Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create an alert dialog
AlertDialog alertB = alertDialogBuilderB.create();
alertB.show();
break;
}
}
}