0

プログレスダイアログを実行するために何時間も座っています....

ここのstackoverflowや他のサイトで非常に多くの例を見ました。

問題:

進行状況ダイアログをアクティビティに配置し、ボタンが押されたときに非同期タスクに渡します。ボタンが押されると、進行状況ダイアログなしでアクティビティが約 2 ~ 3 秒間表示されます。他のアクティビティに切り替えた後、進行状況ダイアログが表示され、非同期タスクが終了した後に終了します。コレオグラファーによると、主な活動は.. 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();
    }
4

2 に答える 2

0

私は問題を解決しました....

私は電話しています

 TabActivity tabs = (TabActivity) getParent();
                    tabs.getTabHost().setCurrentTab(1);

非同期タスクの実行後。完璧に動作します..... 2行のコードと13時間の勉強:-(

于 2013-07-10T09:01:32.150 に答える