我正在为历史课编写一个国家/首都抽认卡应用程序。如果我单击按钮,它会变为大写字母,当我向下滚动然后向上滚动时,它会恢复到状态。我怎样才能阻止这种情况发生?这是我的代码:
package com.example.hostoryflashcards;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class EastEurope extends ListActivity {
String capital[] = {
"Albainia", "Belarus", "Bosina and Herzegouina", "Bulgaria",
"Croatia", "Czech Republic", "Estonia", "Finland", "Greece",
"Hungary", "Kosovo", "Latvia", "Lithuania", "Macedonia", "Molova",
"Montenegro", "Poland", "Romainia", "Russia", "Serbia", "Slovakia",
"Ukraine", "RELOAD"
};
String answer[] = {
"TIRANA", "MINSKA", "SARAJERO", "SOFIA", "ZAGREB", "PRAUGE",
"TALLINN", "HELSINKI", "ATHENS", "BUDAPEST", "PRISTINA", "RIGA",
"VILNIUS", "SKOPJE", "CHISINAU", "PODGORICA", "WARSAW", "BUCHAREST",
"MOSCOW", "BELGRADE", "BRATISLAVA", "LJUBLJANA", "KIEV"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadActivity();
}
private void loadActivity() {
setListAdapter(new ArrayAdapter<String>(EastEurope.this, android.R.layout.simple_list_item_1, capital));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
TextView ov;
ov = (TextView) v;
if (ov.getText().toString() == answer[position]) {
ov.setText(capital[position]);
} else {
ov.setText(answer[position]);
}
}
}