在我的应用程序中,我进行了服务调用以从服务器获取图像。为此,我使用了异步任务类。对于图像加载,我正在使用延迟加载。现在的问题是,当我调用从异步任务的后台方法加载图像时然后屏幕变为空白一段时间,然后我看到进度条。当我对其进行跟踪时,我发现我应该在新线程中开始图像加载。所以我想知道如何在异步任务中启动一个新线程背景方法。请帮助我..我是新手。下面是我的代码..
public class GetRestaurentDetails extends AsyncTask<Object, Object, Object>
{
Context context;
ProgressDialog progressDialog;
public GetRestaurentDetails(Context c) {
this.context=c;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
this.progressDialog=ProgressDialog.show(context,"","Please wait...");
}
@Override
protected Object doInBackground(Object... params) {
onGetRestaurentDetails();
listAdapter = new RestaurantLidtAdapter(arrImages);
setListAdapter(listAdapter);
return null;
}
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
progressDialog.dismiss();
}
}
和适配器类
private class RestaurantLidtAdapter extends BaseAdapter{
Holder holder = null;
LayoutInflater inflater;
ImageLoader imageLoader;
public RestaurantLidtAdapter(ArrayList<String> arrImages){
inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(RestaurantListActivity.this);
}
@Override
public int getCount() {
return arrPromotions.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null){
holder = new Holder();
convertView = (View)inflater.inflate(R.layout.restaurantlistrowlayout, parent, false);
holder.imgArrowImage = (ImageView)convertView.findViewById(R.id.imgArrowInHotelList);
holder.imgHotelImage = (ImageView)convertView.findViewById(R.id.rowHotelImage);
holder.txtRestaurentPromotion = (TextView)convertView.findViewById(R.id.TextViewPromotions);
holder.txtRestaurentName = (TextView)convertView.findViewById(R.id.TextViewRestaurentName);
convertView.setTag(holder);
}
else
{
holder = (Holder)convertView.getTag();
}
//holder.imgHotelImage.setImageBitmap(loadBitmap(arrImages.get(position)));
imageLoader.DisplayImage(arrImages.get(position), holder.imgHotelImage);
holder.txtRestaurentPromotion.setText(arrPromotions.get(position));
holder.txtRestaurentName.setText(arrRestaurentName.get(position));
convertView.setTag(holder);
return convertView;
}
}