Android的 - 创建进度对话框 [英] Android - Create Progress Dialog

查看:102
本文介绍了Android的 - 创建进度对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新android开发。我想开发一个对话框进度在我的应用程序。当我点击搜索按钮对话框应该出现与进度,显示出进度切换到之前回事另一个活动。请给我建议样品code。

I am new to android development. I want to develop a dialog with a progressbar in my application. When i click the search button the dialog should appear with the progressbar, showing that the progress is going on before switching to another activity. Please suggest me with sample code.

推荐答案

使用 ProgressDialog 。你应该做一个新的线程的工作,不过,并使用处理回调到活动时结束。下面是我如何做到这一点:

Use a ProgressDialog. You should do the work on a new thread, though, and use a handler to call back to the activity when finished. Here's how I do it:

private ProgressDialog pd;

private View.OnClickListener searchClick = new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        pd = ProgressDialog.show(MyActivity.this, "Searching...", "Searching for matches", true, false);
        new Thread(new Runnable() {
                public void run() {
                    //do work
                //.....

                finishedHandler.sendEmptyMessage();
                }
            }).start();
    }
}

private Handler finishedHandler = new Handler() {
    @Override public void handleMessage(Message msg) {
        pd.dismiss();
        //start new activity
    }
}

这篇关于Android的 - 创建进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆