0
當我打開某個擴展ArrayAdapter的類時,出現了一些奇怪的情況,當我轉到另一個屏幕時,點擊後退按鈕。我爲某些值設置了膨脹的xml文件的背景應該設置爲灰色(200,200,200)。但是當我現在點擊後退按鈕時,所有東西都是灰色的,儘管當我通過主屏幕(並且沒有按下後退按鈕...)時它顯示效果很好。類看起來像這樣:按下按鈕後不會正常
代碼覆蓋getView方法:
@Override
public View getView(int position, View v, ViewGroup parent) {
View mView = v;
if (mView == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mView = vi.inflate(R.layout.levelselector_item, null);
}
TextView level = (TextView) mView.findViewById(R.id.tvLevel);
TextView levelScore = (TextView) mView.findViewById(R.id.tvLevelScore);
if (mView != null) {
level.setText(Integer.toString(getItem(position).getLevel()));
loadDataBase();
int correctAnswers = myDbHelper.getCorrectAnswers(getItem(position).getLevel());
int correctAnswersPrev = 0;
int correctAnswersPrev = myDbHelper.getCorrectAnswersPrev(getItem(position).getLevel());
String correct = Integer.toString(correctAnswers);
levelScore.setText(correct + "/60");
level.setTypeface(font);
levelScore.setTypeface(font);
if (correctAnswersPrev < 2 && !correct.equals("")){
mView.setBackgroundColor(Color.argb(200, 200, 200, 200));
}
}
return mView;
}
private void loadDataBase() {
// TODO Auto-generated method stub
myDbHelper = new DataBaseHelper(C);
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
} catch (SQLException sqle) {
throw sqle;
}
}
Grtz!
謝謝!它有訣竅。這不奇怪嗎?爲什麼我必須添加一個else語句?如果它的陳述是真實的,那麼假設它只能通過... –
在你知道幕後發生了什麼之前,這很奇怪。觀看Android的Romain Guy討論[本主題](http://www.google.com/events/io/2009/sessions/TurboChargeUiAndroidFast.html),您會發現一些加速代碼的快速提示。很高興我能幫上忙! – Sam