我正在尝试在显示列表视图之前进行进度对话框,因为列表视图上的项目已下载。
我得到这个是因为我正在尝试使用 displayListView(); 更改线程中的列表视图;
02-08 00:25:48.959: W/System.err(3244): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
如果我将 displayListView() 放在我的线程之外,我会得到 nullpointerexeption。displayListView() 使用下载的fieldsList 数组列表。我试图在 myThread.isAlive 时等待,但这样不会显示进度对话框。如何解决?
我的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.build_main);
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setMessage("Loading...");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(0);
dialog.setMax(100);
dialog.show();
Thread myThread = new Thread(new Runnable() {
public void run() {
Builder builder = new Builder(server, user, password, BuildFieldsViewActivity.this, USER_AGENT);
Document doc = null;
doc = builder.DownloadPage("d.php?ne="+gyv_id);
fieldsList = builder.getKaimas(doc);
displayListView();
dialog.setProgress(100);
dialog.dismiss();
}
});
myThread.start();
}