我现在坐了几个小时来运行进度对话框....
我在 stackoverflow 和其他网站上查看了很多示例。
问题:
我正在将进度对话框放入活动中,并在按下按钮时将其移交给异步任务。按下按钮时,活动显示大约 2-3 秒而没有进度对话框,在切换到其他活动后,进度对话框显示并在异步任务完成后终止。Coreographer 告诉我,主要活动.. bla bla ..
// Get Position Button
getPosition = (Button) vg.findViewById(R.id.getPosition);
getPosition.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isAirplaneModeOn(PositionActivity.this) != true) {
try {
// System.out.println("Airplanemode off!");
if (gpsFunc.canGetLocation()) {
SharedPreferences gps = PositionActivity.this
.getSharedPreferences(prefName,
Context.MODE_PRIVATE);
String latlon = gps.getString("coordinates", null);
if (latlon != null) {
String[] split = latlon.split(";");
callWienerLinien();
latitude = Double.parseDouble(split[0]);
longitude = Double.parseDouble(split[1]);
pressed = (TextView) vg
.findViewById(R.id.pressed);
long start = new Date().getTime();
TabActivity tabs = (TabActivity) getParent();
tabs.getTabHost().setCurrentTab(1);
long end = new Date().getTime();
System.out.println(end-start);
} else {
pressed.setText("Bitte Position setzen.");
}
} else {
buildAlertMessageNoDataNetwork();
}
} catch (Exception e) {
errorOccuredMessage();
}
} else {
pressed.setText("Bitte Flugzeugmodus deaktivieren.");
}
}
});
public void callWienerLinien(){
ProgressDialog pd = new ProgressDialog(this);
pd.setMessage("Loading ...");
pt = new PublicTransport(pd,this);
pt.execute("http://webservice.qando.at/2.0/webservice.ft");
}
这是异步任务
public PublicTransport(ProgressDialog pd,Context context){
this.pd = pd;
this.context = context;
getLatLonDestination();
getLatLonOrigin();
}
@Override
protected void onPreExecute(){
super.onPreExecute();
System.out.println("onpre");
pd.show();
}
@Override
protected void onPostExecute(ArrayList<PublicTransportBean> al) {
System.out.println(al.get(0).getTripDuration());
System.out.println("onpostExec");
pd.dismiss();
}