基本上,我希望在活动启动时立即加载纺车,然后在完成后消失。但是,在我当前的代码中,它仅在我按下一个键时才开始。我应该如何替换 onKeyDown 方法,以便一切都自动启动?
@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);
}
};