我正在使用Android Studio將一個pc java代碼移動到android。 java代碼執行一些數字計算例程,並且在基本計算機中可能需要幾秒鐘才能返回問題解決方案。 Java代碼非常漂亮。Android:執行計算時彈出警報
通過點擊按鈕,程序開始。我想知道如何在執行計算時顯示一個優雅的「警報」mensagem。彈出窗口中的一種「請稍等」。
我的基本代碼:
static double h,w,l,t,Te;
static int ambiente;
private EditText numeroin;
//private TextView numeroout;
public void cliqueBotao(View view){
Intent intent = getIntent();
ambiente = intent.getIntExtra("ambiente_selec", 0);
numeroin=(EditText)findViewById(R.id.in_h);
h= Double.parseDouble(numeroin.getText().toString());
numeroin=(EditText)findViewById(R.id.in_w);
w= Double.parseDouble(numeroin.getText().toString());
numeroin=(EditText)findViewById(R.id.in_l);
l= Double.parseDouble(numeroin.getText().toString());
numeroin=(EditText)findViewById(R.id.in_t);
t= Double.parseDouble(numeroin.getText().toString());
numeroin=(EditText)findViewById(R.id.in_T);
Te= Double.parseDouble(numeroin.getText().toString());
(HERE STARTS THE NUMERICAL CALCULATIONS CODE)
/**AlertDialog msg;
msg=new AlertDialog.Builder(this).create();
msg.setMessage("Calculando");
msg.show();*/
}
順便說一句,在按鈕XML代碼的OnClick選項seted爲 「cliqueBotao」。
我不知道AsyncTask類。我是一個「黑屏和白色人物」程序員。我會研究你的建議。 TKS! –
複雜微積分等任何大而緩慢的工作應該在主UI線程之外完成,這就是AsyncTask的用武之地。如果您能夠通過此API建議達到您的需求,請接受我的答案!問候。 –
不錯!但是,發現如何在AsyncTask類中開始新的活動真的是一場戰鬥。最好的答案在這裏:http://stackoverflow.com/questions/12332930/android-asynctask-start-new-activity-in-onpostexecute –