Android 3.1 以降のアプリケーションを開発しています。
私はいくつかのjsonデータをダウンロードするためのこのコードを持っています:
public class FormsListActivity extends ListActivity
{
private List<Form> mForms;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.formlist);
FormListAsyncTask formAsyncTask = new FormListAsyncTask(this);
formAsyncTask.execute("http://192.168.1.128/RestServiceImpl.svc/forms/");
}
private class FormListAsyncTask extends AsyncTask<String, Integer, List<Form>> {
private Context mContext;
private ProgressDialog loadingDialog;
FormListAsyncTask(Context context)
{
mContext = context;
loadingDialog = new ProgressDialog(mContext);
loadingDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
loadingDialog.setMessage("Downloading. Please wait...");
loadingDialog.setCancelable(false);
loadingDialog.setMax(100);
loadingDialog.show();
}
@Override
protected List<Form> doInBackground(String... url)
{
Log.v("doInBackground", "retreiving forms");
return FormSpringController.LoadAll(url[0]);
}
// Just some example code to update your progress dialog
protected void onProgressUpdate(Integer... values)
{
Log.v("onProgressUpdate", "updating: " + ((int) ((values[0] / (float) values[1]) * 100)));
loadingDialog.setProgress((int) ((values[0] / (float) values[1]) * 100));
}
protected void onPostExecute(List<Form> forms)
{
if (forms != null)
{
ListActivity act = (ListActivity) mContext;
act.setListAdapter(new FormAdapter(act, R.layout.form_list_item, forms));
mForms = forms;
}
else
{
TextView errorMsg = (TextView)
((FormsListActivity) mContext).findViewById(R.id.formErrorMsg);
errorMsg.setText("Problem downloading forms. Please try again later.");
}
loadingDialog.dismiss();
}
}
}
onProgressUpdate で loadingDialog の進行状況が更新されないのはなぜですか?