2010년 12월 29일 수요일

Progress Dialog

  1. public class ProgressDialogExample extends Activity implements Runnable {
  2.  
  3.         private String pi_string;
  4.         private TextView tv;
  5.         private ProgressDialog pd;
  6.  
  7.         @Override
  8.         public void onCreate(Bundle icicle) {
  9.                 super.onCreate(icicle);
  10.                 setContentView(R.layout.main);
  11.  
  12.                 tv = (TextView) this.findViewById(R.id.main);
  13.                 tv.setText("Press any key to start calculation");
  14.         }
  15.  
  16.         @Override
  17.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  18.  
  19.                 pd = ProgressDialog.show(this, "Working..", "Calculating Pi", true,
  20.                                 false);
  21.  
  22.                 Thread thread = new Thread(this);
  23.                 thread.start();
  24.  
  25.                 return super.onKeyDown(keyCode, event);
  26.         }
  27.  
  28.         public void run() {
  29.                 pi_string = Pi.computePi(800).toString();
  30.                 handler.sendEmptyMessage(0);
  31.         }
  32.  
  33.         private Handler handler = new Handler() {
  34.                 @Override
  35.                 public void handleMessage(Message msg) {
  36.                         pd.dismiss();
  37.                         tv.setText(pi_string);
  38.  
  39.                 }
  40.         };
  41.  
  42. }

댓글 없음:

댓글 쓰기