显示一个dialog 内有一个progress
package zhang.ProgressDialog;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class pdialog extends Activity {
/** Called when the activity is first created. */
private Button mButton;
private TextView mText;
public ProgressDialog myDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton=(Button)findViewById(R.id.myButton);
mText=(TextView)findViewById(R.id.myTextView);
mButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
final CharSequence strDialogTitle=getString(R.string.str_title);
final CharSequence strDialogBody= getString (R.string.str_body);
myDialog=ProgressDialog.show(pdialog.this,strDialogTitle,strDialogBody,true);
mText.setText(strDialogBody);
new Thread(){
public void run(){
try{
sleep(3000);
}
catch(Exception e){
e.printStackTrace();
}finally{
myDialog.dismiss();
}
}
}.start();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:id="@+id/myTextView"/>
<Button
android:text="点我启动ProgressDialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myButton"/>
</LinearLayout>