【问题标题】:Insert progress spinner into splashscreen android将进度微调器插入启动画面android
【发布时间】:2010-09-20 19:06:35
【问题描述】:

在我的 android 应用程序中,我想放置一个进度条,以便它向用户显示数据正在下载并在数据加载后被关闭。

有没有什么方法可以实现。

提前致谢:)

【问题讨论】:

    标签: android


    【解决方案1】:

    你可以通过AsyncTask类来实现。

    在这三个步骤中,您必须遵循,

    1. 您必须在 onPreExecute() 中启动 ProgreesDialog。
    2. doInBackground() 控制下载进度。
    3. onPostExcecute() 在第二步之后运行。您可以关闭进度对话框,启动新活动并完成启动画面。

    更多信息,请查看Documentation。它有示例代码的解释。

    代码:

      private class Task extends AsyncTask<Void, Void, Void> {
        private final ProgressDialog dialog = new ProgressDialog(
                your_class.this);
    
        // can use UI thread here
        protected void onPreExecute() {
            this.dialog.setMessage("Loading...");
            this.dialog.setCancelable(false);
            this.dialog.show();
        }
    
        @Override
        protected Void doInBackground(Void... params) {
            try {
                // do downloading images code here
            } catch (Exception e) {
    
            }
            return null;
    
        }
    
        protected void onPostExecute(Void result) {
               //start the another activity and then close your current activity here.
            if (this.dialog.isShowing()) {
                this.dialog.dismiss();
            }
        }
    }
    

    【讨论】:

    • 谢谢Praveen。如果你有任何示例代码,你能提供给我吗?
    • @Reshmi:请查看文档链接。我已经在回答中提到了。
    • 感谢Praveen。示例代码是从url下载文件,但需要从本地项目下载文件。是否可以相同。
    • 对不起,如果我的怀疑很愚蠢,但我是新手,无法做到
    • @Reshmi:嘿,我添加了一些代码 sn-p。希望它可以帮助你。还有一件事,当你对任何人发表评论时。评论喜欢这种格式@username: your comment。它为他们唤醒通知。它有助于获得快速响应。 ;)
    猜你喜欢
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2016-10-08
    相关资源
    最近更新 更多