基本上,我想要在活動開始時立即將紡車加載,然後在完成時消失。但是,在我當前的代碼中,只有在按下某個鍵時纔會啓動。我應該如何替換onKeyDown方法,以便所有內容自動啓動?如何更換KeyEvent?
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
pd = ProgressDialog.show(this,"Working", "Fetching Grades", true,
false);
Thread thread = new Thread(this);
thread.start();
return super.onKeyDown(keyCode, event);
}
public void run(){
//String userthat = userThing.getText().toString();
//String passthis = passThing.getText().toString();
thisthing = new ClientLoginForm(user2s,pas2s);
try{
grades +=thisthing.returnGradies();
} catch (Exception e){
grades +="Connection Problems";
}
handler.sendEmptyMessage(0);
}
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg){
pd.dismiss();
tv.setText(grades + "\n " + pas2s + " " + user2s);
}
};
那麼,爲什麼你把代碼放在onKeyDown()方法? – 2012-02-14 12:28:43