【问题标题】:Show Progress Dialog before loading ListView contents在加载 ListView 内容之前显示进度对话框
【发布时间】:2012-06-18 14:14:16
【问题描述】:

我正在从文件中读取数据 -> 保存到数据库中 -> 通过从数据库中获取数据来加载我的自定义列表视图。在获取数据并将数据保存到数据库时,我希望 ProgressDialog 出现在我的屏幕上,我尝试了这两种类型 但它不起作用

类型 1:

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

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

alertDialog.dismiss();

类型 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();

我尝试了两种方法都不起作用,ProgressDialog 没有出现在屏幕上,我在代码中添加的任何其他内容或我需要做的任何修改,请帮助我...

注意:当忘记调用dismiss();在 ListView 加载后出现 Type 1 Progress 并旋转无限时间..

【问题讨论】:

  • 使用异步任务来获取、保存在数据库中并在列表视图中设置。在异步任务的预执行中启动您的警报对话框并在执行后关闭您的对话框
  • 谢谢,我的代码中是否有任何线程问题,我无法指出请帮助我

标签: android multithreading progressdialog


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    相关资源
    最近更新 更多