2010-08-07 23 views

回答

4

使用AsyncTask,填充onPostExecute()中的列表視圖。

http://www.screaming-penguin.com/node/7746

private class InsertDataTask extends AsyncTask<Void, Void, Void> { 

    private final ProgressDialog dialog = new ProgressDialog(Main.this); 

    // can use UI thread here 
    protected void onPreExecute() { 
    this.dialog.setMessage("Inserting data..."); 
    this.dialog.show(); 
    } 
    // automatically done on worker thread (separate from UI thread) 
    protected Void doInBackground(final String... args) { 
    //do something in background, i.e. loading data 
    return null; 
    } 

    // can use UI thread here 
    protected void onPostExecute(final Void unused) { 
    if (this.dialog.isShowing()) { 
     this.dialog.dismiss(); 
    } 
    // populate list here 
    } 
} 

...

new InsertDataTask().execute(); 

也很有幫助: http://developer.android.com/resources/articles/painless-threading.html

+0

我使用你的答案在這裏搜索位置,但'ProgressDialog」出現很簡單,是立即解散(幾乎像閃光)。我希望它保持顯示,直到找到位置。請告訴我如何做到這一點。 – Emzor 2016-01-18 17:43:02

相關問題