简体   繁体   中英

Show Progress Dialog before loading ListView contents

I'm reading data from a file -> saving into DB -> Loading my Custom ListView by fetching data from DB.. While Fetching and Saving Data to DB i want to ProgressDialog to appear on my screen i tried these two type but its not working

Type 1:

AlertDialog alertDialog = AlertDialog.show(CommoditiesListScreen.this, "Importing...");

// importing data from file
// Saving data to the DB

alertDialog.dismiss();

Type 2:

 UiDialog uiDialog = new UiDialog(CommoditiesListScreen.this);
 CommoditiesListScreen.this.runOnUiThread(uiDialog);
 AlertDialog alertDialog = AlertDialog.show(CommoditiesListScreen.this, "Importing...");
 alertDialog.getWindow().makeActive();


// importing data from file
// Saving data to the DB

uiDialog.stopDialog();
alertDialog.dismiss();

I tried in both ways it not working, ProgressDialog is not appearing on the screen, Anything else i've add or any modification i've to do in my cod eplease help me...

Note: When Forgot call dismiss(); in Type 1 Progress appears after ListView loaded and it spins for infinite time..

这是使用AsyncTask的理想情况,您可以在方法onPreExecute()显示dialog ,在方法onPreExecute()中执行后台操作(从文件读取数据 - >保存到DB doInBackground()并加载并显示列表onPostExecute()方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM