Android:执行计算时弹出警报
问题描述:
我正在使用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”。
答
正如Rogério所建议的,AsyncTask是解决我的问题的最佳解决方案。另一方面,我不得不通过使用AsyncTask来发现如何开始一个新的活动。这对我来说并不容易,但一个有用的解决方案在这里:Android AsyncTask: start new Activity in onPostExecute()
我不知道AsyncTask类。我是一个“黑屏和白色人物”程序员。我会研究你的建议。 TKS! –
复杂微积分等任何大而缓慢的工作应该在主UI线程之外完成,这就是AsyncTask的用武之地。如果您能够通过此API建议达到您的需求,请接受我的答案!问候。 –
不错!但是,发现如何在AsyncTask类中开始新的活动真的是一场战斗。最好的答案在这里:http://*.com/questions/12332930/android-asynctask-start-new-activity-in-onpostexecute –