我有一个数组代表迷宫。在UI上,迷宫被表示为按钮的行和列。在异步任务的doInBackground方法中,我搜索了一个路径并用导致目标的路径初始化一个解决方案数组。我想要做的是更新这些按钮的按钮文本,以显示通向目标的路径。我在OnPostExecute中这样做。但是,它不起作用。它甚至不执行启用解决方案按钮的最后一行。我在哪里做什么?从OnPostExecute更新UI(异步)
private void updateUI() {
Button cell;
TableRow row;
do {
row = (TableRow) (State.maze.getChildAt(solution.row));
cell = (Button) (row.getChildAt(solution.col));
cell.setText(State.pathCell);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
solution = solution.next;
} while (solution.next != null);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
updateUI();
//Enable solution button
State.solveResetButton.setEnabled(true);
}
更新: 我检查,以确保解决方案变量包含一个解决方案,它包含有效data.I还试图消除睡眠,但无济于事。
UPDATE: logcat的输出(在红色的)
02-23 13:09:15.471 4640-4640/? E/Zygote: MountEmulatedStorage()
02-23 13:09:15.471 4640-4640/? E/Zygote: v2
02-23 13:09:15.471 4640-4640/? E/Zygote: accessInfo : 0
02-23 13:09:15.471 4640-4640/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
是否有您的logcat的任何异常做到这一点? – Lal
一个简单的解决方案将可用,如果你可以调试它.. – Lal
你可以发布你的所有代码,你是否在串行Executor上运行AsyncTask? –