資源描述:
《listview異步加載之優(yōu)化篇》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在行業(yè)資料-天天文庫。
1、Listview異步加載之優(yōu)化篇??異步加載圖片基本思想:1.??????先從內(nèi)存緩存中獲取圖片顯示(內(nèi)存緩沖)2.??????獲取不到的話從SD卡里獲?。⊿D卡緩沖)3.??????都獲取不到的話從網(wǎng)絡下載圖片并保存到SD卡同時加入內(nèi)存并顯示(視情況看是否要顯示)1.public?class?LoaderAdapter?extends?BaseAdapter{??2.??3.????private?static?final?String?TAG?=?"LoaderAdapter";??4.????private?boolean?mBu
2、sy?=?false;??5.??6.????public?void?setFlagBusy(boolean?busy)?{??7.????????this.mBusy?=?busy;??8.????}??9.??10.??????11.????private?ImageLoader?mImageLoader;??12.????private?int?mCount;??13.????private?Context?mContext;??14.????private?String[]?urlArrays;??15.??????16.???
3、???17.????public?LoaderAdapter(int?count,?Context?context,?String?[]url)?{??18.????????this.mCount?=?count;??19.????????this.mContext?=?context;??20.????????urlArrays?=?url;??21.????????mImageLoader?=?new?ImageLoader(context);??22.????}??23.??????24.????public?ImageLoade
4、r?getImageLoader(){??25.????????return?mImageLoader;??26.????}??27.??28.????@Override??29.????public?int?getCount()?{??30.????????return?mCount;??31.????}??32.??33.????@Override??34.????public?Object?getItem(int?position)?{??35.????????return?position;??36.????}??37.??1.
5、????@Override??2.????public?long?getItemId(int?position)?{??3.????????return?position;??4.????}??5.??6.????@Override??7.????public?View?getView(int?position,?View?convertView,?ViewGroup?parent)?{??8.??9.????????ViewHolder?viewHolder?=?null;??10.????????if?(convertView?==
6、?null)?{??11.????????????convertView?=?LayoutInflater.from(mContext).inflate(??12.????????????????????R.layout.list_item,?null);??13.????????????viewHolder?=?new?ViewHolder();??14.????????????viewHolder.mTextView?=?(TextView)?convertView??15.????????????????????.findView
7、ById(R.id.tv_tips);??16.????????????viewHolder.mImageView?=?(ImageView)?convertView??17.????????????????????.findViewById(R.id.iv_image);??18.????????????convertView.setTag(viewHolder);??19.????????}?else?{??20.????????????viewHolder?=?(ViewHolder)?convertView.getTag();?
8、?21.????????}??22.????????String?url?=?"";??23.????????url?=?urlArrays[position?%?urlArrays.length];??2