在我onPause我收集問題行和可見的按鈕數。然後在onResume中使用這些來恢復用戶所在的位置。底部的代碼是用於問題的,並且工作正常。問題在於可見的按鈕。 If語句被忽略。 Logcat告訴我,重新調整的可見按鈕(在這種情況下)的值是3,但它被忽略。我嘗試了不同的方法,例如在if語句之前將「vis」轉換爲整數纔會產生numberformat異常。這個當前的代碼是爲if語句的字符串聲明值,但無濟於事。我希望有人能指出我正確的方向。親切的問候德里克如果陳述被忽略
private void restoreVis() {
int i = 2;
int j = 3;
String strI = String.valueOf(i);
String strJ = String.valueOf(j);
String file1 = "vis";
try {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(
openFileInput(file1)));
String inputString;
StringBuffer stringBuffer = new StringBuffer();
while ((inputString = inputReader.readLine()) != null) {
stringBuffer.append(inputString + "\n");
}
String vis = stringBuffer.toString();
Log.i(LOGTAG, vis + " visible buttons");
if (vis.equals(strI)) {
eliminateChooser();
eliminateChooser();
Log.i(LOGTAG, "equals 2");
} else if (vis.equals(strJ)) {
eliminateChooser();
Log.i(LOGTAG, "equals 3");
}else{
Log.i(LOGTAG, "vis equals 4");
}
} catch (IOException e) {
e.printStackTrace();
}
Log.i(LOGTAG," end of vis");
}
LogCat
06-20 17:50:07.603: I/ON(18818): 3 visible buttons
06-20 17:50:07.608: I/ON(18818): vis equals 4
06-20 17:50:35.513: I/ON(18818): on Pause called
06-20 17:50:35.513: I/ON(18818): 8 row Id
06-20 17:50:35.513: I/System.out(18818): Visible children: 4
private void restoreGameState() {
String file = "row";
try {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(
openFileInput(file)));
String inputString;
StringBuffer stringBuffer = new StringBuffer();
while ((inputString = inputReader.readLine()) != null) {
stringBuffer.append(inputString + "\n");
}
String row = stringBuffer.toString();
quest = datasource.findGameState(null, row);
refreshDisplay();
Log.i(LOGTAG, row + " value of rowId");
} catch (IOException e) {
e.printStackTrace();
}
}
您的file1似乎不正確。我認爲它必須像「vis.txt」,沒有文件結尾 – Opiatefuchs