public View getView(final int position, View convertView, ViewGroup parent) {
SectionHolder sectionHolder = null;
ViewHolder holder = null;
convertView = listAdapter.getView(getIndexForPosition(position),
convertView, parent);
convertView.setTag(contactsIds[getIndexForPosition(position)]);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView
.findViewById(R.id.list_item_title);
holder.id = contactsIds[getIndexForPosition(position)];
new ThumbnailTask(holder,contactsIds[getIndexForPosition(position)]).execute();
return convertView;
}
private class ThumbnailTask extends AsyncTask<Void, Void, Integer> {
private String mId;
private ViewHolder mHolder;
public ThumbnailTask(ViewHolder holder, String id) {
mId = id;
mHolder = holder;
}
@Override
protected Integer doInBackground(Void... params) {
// TODO Auto-generated method stub
int drawableId = getContactStatus(mHolder.id);
// Log.i("DRAWABLE",drawableId+"");
return drawableId;
}
protected void onPostExecute(Integer drawableId) {
if (mHolder.id.equals(mId)) {
if (drawableId != 0) {
if (UpdateStatusService.user == 1) {
mHolder.txtTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0,drawableId, 0);
} else {
mHolder.txtTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0,R.drawable.ic_action_quetion, 0);
}
} else {
mHolder.txtTitle.setCompoundDrawablesWithIntrinsicBounds(0,0, android.R.color.transparent, 0);
}
}
}
}
static class ViewHolder {
public TextView txtTitle;
public String id;
}
这是我的列表视图getView的适配器代码。
ListView 包含来自 android 的联系人列表。
但我得到java.util.concurrent.RejectedExecutionException 异步任务基本上是从服务器获取图像,如果有任何数字与将包含一个图像的服务器数据匹配,否则将不设置。
那么我应该怎么做才能避免这个异常呢?