我在项目中有一个expandableListView。如果有人点击该组,那么必须加载数据并且必须加载进度条的加载时间。我想通过异步任务来完成。请给我示例代码。 提前谢谢。
答案 0 :(得分:33)
请试试这个
public class LoadData extends AsyncTask<Void, Void, Void> {
ProgressDialog progressDialog;
//declare other objects as per your need
@Override
protected void onPreExecute()
{
progressDialog= ProgressDialog.show(YourActivity.this, "Progress Dialog Title Text","Process Description Text", true);
//do initialization of required objects objects here
};
@Override
protected Void doInBackground(Void... params)
{
//do loading operation here
return null;
}
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
progressDialog.dismiss();
};
}
您可以使用
调用此方法LoadData task = new LoadData();
task.execute();