Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur

13 Haziran 2011 Pazartesi

Handler kullanarak Thread içinden UI bileşenine mesaj işlemek

Ref: http://www.helloandroid.com/tutorials/using-threads-and-progressdialog

public class ProgressDialogExample extends Activity implements Runnable {

private String pi_string;
private TextView tv;
private ProgressDialog pd;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

tv = (TextView) this.findViewById(R.id.main);
tv.setText("Press any key to start calculation");
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

pd = ProgressDialog.show(this, "Working..", "Calculating Pi", true,
false);

Thread thread = new Thread(this);
thread.start();

return super.onKeyDown(keyCode, event);
}

public void run() {
pi_string = Pi.computePi(800).toString();
handler.sendEmptyMessage(0);
}

private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss();
tv.setText(pi_string);

}
};
}

Hiç yorum yok: