ProgressDialog的一点经验

在开发过程中发现这样的问题:
  我是用的是圆形进度条对话框,在Acitivity中第一次调用显示这个圆形进度条对话框的时候,圆形进度条的显示一切正常。可是在将这个进度条对话框隐藏后,并再次显示时,对话框上的圆形进度条就不转了。经过试验,解决方法如下:

package com.example.android.apis.view;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

import com.example.android.apis.R;

public class ProgressBar3 extends Activity {

    private static final int DIALOG1_KEY = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.progressbar_3);

        Button button = (Button) findViewById(R.id.showIndeterminate);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	showDialog(DIALOG1_KEY);
            	//mDialog1.cancel();
            }
        });
    }
    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case DIALOG1_KEY: {
            	ProgressDialog temp = new ProgressDialog(this);
            	temp.setOnKeyListener(new OnKeyListener(){

					@Override
					public boolean onKey(DialogInterface dialog, int keyCode,
							KeyEvent event) {
						// TODO Auto-generated method stub
						removeDialog(DIALOG1_KEY);
						return true;
					}
            		
            	});
            	return temp;
            }
        }
        return null;
    }
}

removeDialog(DIALOG1_KEY); 是解决该问题的关键。

我的sdk是LeOs 2.0 不知道其他版本的sdk编出的程序是否有这个问题。

你可能感兴趣的:(android,OS)