Android:在使用Dialog扩展的类中显示进度对话框

时间:2011-09-07 06:37:45

标签: android progressdialog

我有一个用Dialog本身扩展的类。对话框中有一些可用于向服务器发送请求的选项。我想在用户点击任何此类选项时显示进度等待对话框。

但是没有显示的Dialog可能是因为我在对话框中显示了一个进度对话框。

代码非常简单。

public class LeaderBoard extends Dialog implements View.OnClickListener {
public LeaderBoard(Context context) {
        super(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        this.mContext = context;

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.leaderboard);

public void onClick(View paramView) {
..............
if (this.waitDialog != null) {
            this.waitDialog.show();
        }
new Runnable() {

                    @Override
                    public void run() {

                        mHandler.post(new Runnable() {

                            @Override
                            public void run() {
                                send request to server
                                waitDialog.dismiss();
                            }
                        });

                    }
                }.run();

1 个答案:

答案 0 :(得分:1)

您好请尝试以下代码。

public class LeaderBoard extends Dialog implements View.OnClickListener {
Activity mActivity;
private final ProgressDialog dialog;
public LeaderBoard(Activity activity) {
        super(activity, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        mActivity = activity;

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.leaderboard);
        dialog = new ProgressDialog(mActivity);

public void onClick(View paramView) {
..............
if (this.waitDialog != null) {
            this.dialog.setMessage("Please Wait...");
            this.dialog.show();
        }
new Runnable() {

                    @Override
                    public void run() {

                        mHandler.post(new Runnable() {

                            @Override
                            public void run() {
                                send request to server
                                this.dialog.dismiss();
                            }
                        });

                    }
                }.run();

谢谢, NIK ...