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;
}
這是我的適配器代碼,用於查看listview。異步任務中的java.util.concurrent.RejectedExecutionException Android
ListView包含來自android的聯繫人列表。
,但我得到java.util.concurrent.RejectedExecutionException 異步任務基本上都是從服務器獲取圖像,如果任何數量的匹配將包含一個圖像的設置,否則不是服務器的數據。
那麼我該怎麼做才能避免這種異常?
我認爲[這](http://www.google.com/search?q=java.util.concurrent.RejectedExecutionException&ie=utf-8&oe=utf-8&aq=t)將給任何解決方案。 – Praveenkumar
你有多少聯繫人?我認爲getView被調用了很多,並且阻塞了asynctask隊列。你不應該在每個getView中調用它,因爲它每行被調用幾次 – njzk2
那麼我怎麼實現「在getView()之外的列表視圖中加載圖像」? –