2012-01-15 36 views
0

我正在創建一個Android應用程序,並計劃使用進度條作爲我的應用程序的介紹。你可以跟我分享一些使用進度條作爲第一個視圖的教程嗎?然後進入新視圖,如果進度條完成使用進度條在android中的第一個視圖

+0

您是否在顯示進度條或者只是想顯示它時加載任何信息? – 2012-01-15 03:55:00

+0

是的,如果有可能先生 – Vhal 2012-01-15 04:05:02

回答

0

我會推薦的是使用AsyncTask。這將允許你做後臺工作並通過進度條更新UI。

所以這裏是一個關於如何使用它的快速教程。

private class InsertDataTask extends AsyncTask<Void, Void, Void> { 
    private final ProgressDialog dialog = new ProgressDialog(Main.this); 

    // can use UI thread here, and you see we add a progress dialog 
    protected void onPreExecute() { 
    this.dialog.setMessage("Inserting data..."); 
    this.dialog.show(); 
    } 

// automatically done on worker thread (separate from UI thread) 
    protected Void doInBackground(Void... args) { 
    //Do background work here 
    return null; 
    } 

    // can use UI thread here and we dismiss the progress dialog 
    protected void onPostExecute(final Void unused) { 
    if (this.dialog.isShowing()) { 
     this.dialog.dismiss(); 
    }