私は 3 つの長い操作を実行する必要があるクラスを持っています。また、25%、50%、75%、および 100% の間隔で進行状況バーを表示する必要があります。
操作は UI スレッドを使用するため、DoinBackground メソッド () に配置することはできません。
操作を進行中のUpdateメソッドに配置しています
コード
package com.integrated.mpr;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.stat.correlation.Covariance;
import org.apache.commons.math.stat.correlation.PearsonsCorrelation;
import org.apache.commons.math.util.FastMath;
public class Logic extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.progress);
String x = "abc";
new loadSomeStuff().execute(x);
}
public class loadSomeStuff extends AsyncTask<String,Integer,String>{
ProgressDialog dialog;
protected void onPreExecute(){
dialog = new ProgressDialog(Logic.this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMax(100);
dialog.show();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
publishProgress(25);
publishProgress(50);
publishProgress(75);
publishProgress(100);
return null;
}
protected void onProgressUpdate(Integer...progress){
if(progress[0]==25){
dialog.incrementProgressBy(25);
Log.d("now in ", "25 loop");
// do some long work in loop1
dialog.incrementProgressBy(25);
}
else if(progress[0]==25){
dialog.incrementProgressBy(25);
Log.d("now in ", "50 loop");
// do some long work in loop2
dialog.incrementProgressBy(25);
}
else if (progress[0] == 75){
dialog.incrementProgressBy(25);
// do some long work in loop3
}
else{
dialog.incrementProgressBy(25);
}
}
protected void onPostExecute(String result){
dialog.dismiss();
Intent openList = new Intent("com.integrated.mpr.SENSITIVELIST");
startActivity(openList);
}
}
}
これを実行すると、空白の画面が表示され、進行状況が 100% だけ表示されます。どうすればこれを修正できますか?? 助けてください