2

これで提案を使用しましが、まだ同じ問題があります。AsyncTask の使用を提案してくれた友人に感謝しますが、うまくいきません。何?これは私のコードです:

DBAsyncTask dba = new DBAsyncTask(this, xmlCommand);
    dba.inProcess = true;
    dba.execute("");
    while (dba.inProcess) {
        try {
            Thread.sleep(200);
            println("wwwwait");
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public class DBAsyncTask extends AsyncTask<String, Void, String> {
    public boolean inProcess;

    public DBAsyncTask(ExirCommandRunner commandRunner,XmlNode xmlCommand) {
        this.commandRunner = commandRunner;
        this.xmlCommand = xmlCommand;

    }

    @Override
    protected void onPostExecute(String result) {
        ExirDebugger.println("onPostExecute");
    }

    @Override
    protected void onPreExecute() {
        showProgress();
    }

    @Override
    protected String doInBackground(String... params) {
    ///my process here 
        closeProgress();
        return null;
    }

誰でも私を助けることができますか?

4

3 に答える 3

3

Thread.sleep()UI スレッドをブロックするため、進行状況ダイアログを実行できません。inProcessそれとポーリングメカニズムを削除します。また、進行状況ダイアログで非同期タスクを使用する方法については、多くの参照があります。

于 2013-08-01T06:05:04.073 に答える
1

次のようになります。

protected void onPreExecute() {
            super.onPreExecute();
             pDialog = new ProgressDialog(activityContext);
             pDialog.setCancelable(false);
             pDialog.setMessage("Please Wait..");
             pDialog.show();
        }

protected void onPostExecute(String file_url) 
        {
            if(pDialog.isShowing())
            {
                pDialog.cancel();
            }
                }
于 2013-07-31T13:00:07.730 に答える