一.Activity的啟動模式? 兩種方式四種模式
(1)在清單文件中,標簽中配置android:launchMode=""屬性
? ? ?四個屬性值:
? ? ?<1>standard:
? ? ? ? ? ? ? ? ? ? ? ? ? ? 默認的? 可以實例化多次,每次啟動都會創(chuàng)建一個新的實例
? ? ?<2>singleTop:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?可以實例化多次,當其在棧頂時,只能創(chuàng)建一個實例
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?當棧頂存在要啟動的Activity實例時,系統(tǒng)會調(diào)用onNewIntent()方法
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?把Intent對象傳遞給已經(jīng)存在的Activity實例,從而重用棧頂?shù)腁ctivity
? ? ? <3>singleTask:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 棧內(nèi)部只能有一個Activity實例,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 解釋一:當?shù)诙螁釉揂ctivity時,系統(tǒng)會從上到下依次尋找該Activity已有的實例,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 找到會移除它之上的所有Activity實例,并重用該Activity實例
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 解釋二:當棧中存在要啟動的Activity實例時,系統(tǒng)會調(diào)用onNewIntent() 方法
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 把Intent對象傳遞給已經(jīng)存在的Activity實例,從而重用該Activity實例
? ? ? ?<4>singleInstance:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 系統(tǒng)會單獨分配一個任務(wù)棧,并把它的實例放到棧底,不和別的Activity共享一個棧
(2)在Activity類中通過Intent對象設(shè)置啟動模式,優(yōu)先級高于上面的方式
? ? ? ? Intent intent = new Intent();
? ? ? ? intent.setFlags(Intent.參數(shù));
參數(shù):
? ? ? ? ? 默認? ? ? ? ? ? ? ? ? ? ? 等同于standard
? ? ? ? ? FLAG_ACTIVITY_SINGLE_TOP? 等同于singleTop
? ? ? ? ? FLAG_ACTIVITY_CLEAR_TOP? 等同于singleTask
? ? ? ? ? FLAG_ACTIVITY_NEW_TASK? ? 等同于singleInstance
? ? ? ? ? 如果是代碼中設(shè)置啟動模式:NEW_TASK,則必須在清單文件中加上下面屬性
? ? ? ? ? android:taskAffinity="com.other"
? ? ? ? ? android:allowTaskReparenting="true"
? ? ? ? ? 否則不起作用
二.Intent七大屬性
(1)Intent的作用
? ? ? 包裝android的組件
? ? ? 啟動Activity ,啟動Service,發(fā)送廣播
? ? ?組件之間的傳值
(2)顯示意圖------setClass()
? ? ? ? ? ? ? ? ? ? ?------setComponent();
明確指定要跳轉(zhuǎn)到哪個Activity(通常用于啟動應(yīng)用內(nèi)部的Activity)
寫法一: Intent intent = new Intent(MainActivity.this,InfoActivity.class);
寫法二: Intent intent= new Intent();
? ? ? ? ? ? ? ? ?intent.setClass(MainActivity.this,InfoActivity.class);
寫法三:? ComponentName 包裝Android組件
? ? ? ? ? ? ? ?Intent intent = new Intent();
? ? ? ? ? ? ? ?ComponentName cn = new? ComponentName(MainActivity.this,InfoActivity.class);
? ? ? ? ? ? ? ?intent.setComponent(cn);
(3)隱身意圖------action? ? ??
? ? ?不明確指定目標Activity署驻,而是通過Intent的動作action(通常用于多個應(yīng)用程序之間的跳轉(zhuǎn))? ? ??
? ? ?必須在android應(yīng)用中保持唯一? ? ??
? ? 目標Activity中必須聲明action屬性
? ? ?<intent-filter>
? ? ? ? ? ?<action ? android:name="com.qf.day06_lunchmode.CActivity"/>
? ? ? ? ? ?<category ?android.intent.category.DEFAULT"/>
? ? ?</intent-filter>
注意:action屬性一般需要和category屬性一起使用
訪問者:
方式一: Intent intent=new ?Intent();
? ? ? ? ? ? ? ? Intent();intent.setAction("com.qf.day06_lunchmode.CActivity");? ? ? ??
方式二:? ? ? ? ? ? ? ??
? ? ? ? ? ? ? Intent intent? = new Intent("com.qf.day06_lunchmode.CActivity"); ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? android.setting.SETTINGS 設(shè)置頁面
? ? ? ? ? ? ? Intent.ACTION_DIAL? ? ? 撥號頁面
? ? ? ? ? ? ? Intent.ACTION_CALL? ? ? 撥打電話(直接呼出)
(4)category:表示action組件啟動的類型
? ? ? ? ? ? 一般android.intent.category.DEFAULT 代表普通的Activity組件
(5)data屬性:指定action后,將必須的屬性設(shè)置在此屬性中
? ? ? ? ? 如:打電話? 必須提供電話號碼
? ? ? ? ? ? ? ?打開網(wǎng)頁? ? 網(wǎng)址
? ? ? ? ?URI? 統(tǒng)一資源標識
? ? ? ? ? ? ? ? ?打電話: tel:53435343443
? ? ? ? ? ? ? ? ?發(fā)短信: smsto:760439045
? ? ? ? ? ? ? ? ?網(wǎng)址:? http://www.baidu.com
(6)type屬性:
? ? ? ? ? ?如果data屬性是文件的路徑,必須通過type來指定文件的類型
? ? ? ? ? ?圖片:? image/*
? ? ? ? ? ?文本:? text/*
? ? ? ? ? ?視頻:? video/*
? ? ? ? ? ?音頻:? audio/*
(7)extra 屬性:除了必須的屬性之外的擴展信息的屬性
? ? ? ? ? ? ? 常用于Android組件之間傳遞數(shù)據(jù)
(8)flag:組件的啟動模式 (參考Activity的啟動模式)
? ? ? ? ? ? 廣播接收器,啟動Activity組件式,必須指定flag屬
? ? ? ? ? ?性:FLAG_ACTIVITY_NEW_TASK
三.AsyncTask的使用
(1)定義一個類,繼承AsyncTask類,同時聲明三個泛型? ? ??
public class MyAsyncTask extends AsyncTask<String,Integer,Byte[]>
第一個參數(shù):? 子線程執(zhí)行方法的參數(shù)類型,對應(yīng)doinbackground的參數(shù)
第二個參數(shù):? 子線程執(zhí)行方法的進度,? ? 對應(yīng)onProgressUpdate的參數(shù)? 可以為空,Void首字母應(yīng)該大寫
第三個參數(shù):? 子線程執(zhí)行任務(wù)的結(jié)果返回類型,對應(yīng)onPostExecute的參數(shù)和doInbackground的返回值
(2)AsyncTask的四個核心方法(重寫)
? ? ? ? //運行在主線程中,執(zhí)行異步任務(wù)時,首先調(diào)用的方法,用于初始化
? ? ? ?<1>protected void onPreExecute()//運行在子線程中,執(zhí)行耗時的操作(后臺線程)
? ? ? ?<2>protected byte[] doInBackground(String... params)//運行在主線程中,用于更新 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 進度,更新前必須先手動 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 調(diào)用publishProgress()方 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?法
? ? ? <3>protected void onProgressUpdate(Integer...values)//運行在主線程中,在 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? doInbackground方法之后 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 執(zhí)行,系統(tǒng)自動調(diào)用
? ? ? <4>protected void onPostExecute(byte[] result)
(3)利用回調(diào)接口來實時更新進度
<1>定義一個回調(diào)接口
? ? ? ?public interface CallBack{
? ? ? ? ? ? ? ? ? ? ?public void callBack(int progress);回調(diào)方法,參數(shù)為進度的百分比
? ? ? ?}
<2>在訪問網(wǎng)絡(luò)的工具中聲明回調(diào)接口(HttpUtils工具類)
public? static String getJson(String path,CallBack callback){//以加載json字符串為例
? ? ? ? ? //獲取網(wǎng)絡(luò)資源的代碼
? ? ? ? ?//調(diào)用CallBack接口中的回調(diào)方法傳回進度
? ? ? ? ?callback.callBack(progress);
}
<3>在doInBackground方法中調(diào)用getJson方法,同實例化一個CallBack接口的匿名內(nèi)部類
protected byte[] donInBackground(String ... params){
? ? ? ? ? ?HttpUtils.getJson(params[0],new CallBack(){
? ? ? ? ? ? ? ? ? ? ? ? ? ? public void callBack(int progress){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//當獲取網(wǎng)絡(luò)資源的代碼中調(diào)用此回調(diào)接口時,觸發(fā)此處代碼,并 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?傳回進度
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //拿到進度值,更新進度條
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? publishProgress(progress); //該方法將觸發(fā) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?onProgressUpdate(Integer..values);方法
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ?});
}
(4)取消異步任務(wù)
? ? ? ? (1)調(diào)用task.cancel(true);//true表示暴力取消,false溫柔取消
? ? ? ? (2)溫柔取消時系統(tǒng)會自動執(zhí)行onCancelled()方法
? ? ? ? ? ? ? protected void onCancelled() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if(isCancelled()){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "任務(wù)被取消!", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Toast.LENGTH_LONG).show();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? }
四.ListView的總結(jié)
(1)主要屬性:
? ? ? ? ? ? ? ? ? android:divider = "#rgb"? Item之間的分割線的顏色,也可以是一張圖片
? ? ? ? ? ? ? ? ? android:dividerHeight = "1dp" Item之間的距離,通常為1dp
? ? ? ? ? ? ? ? ? android:entries="@array/name"? 用數(shù)組填充Item
(2)填充方式:? ? ??
? ? ? ? ?<1>屬性填充:? ? ? ? ??
? ? ? ? ? ? ? ? step1:先在strings.xml中定義數(shù)組
? ? ? ? ? ? ? ? ? ? ? ? ? ?<string_array name="citys">
? ? ? ? ? ? ? ? ? ? ? ? ? ?<item>北京</item>
? ? ? ? ? ? ? ? ? ? ? ? ? ?</string_array>
? ? ? ? ? ? ? ?step2:在listView中添加entries屬性? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? android:entries="@array/citys"
? ? ? ? ? ?<2>在Activity中通過適配器填充? ? ? ? ??
? ? ? ? ? ? ? ? ?①ArrayAdapter填充,適用于Item中只有一個文本? ? 數(shù)據(jù)源為:List<String>
? ? ? ? ? ? ? ? ?②SimpleAdapter填充,可以實現(xiàn)圖文混排的效果,但圖片必須是本地的(不能是從網(wǎng)絡(luò)獲取的)? ? 數(shù)據(jù)源為:List<Map<String,Object>>
?③自定義Adapter,創(chuàng)建自己的Adapter類繼承BaseAdapter抽象類,實現(xiàn)抽象方法? ? 數(shù)據(jù)源為:List<Map<String,Object>>或者ListM<javaBean>
? ? ? ? ?Step1:定義一個類繼承BaseAdapter
? ? ? ? ?Step2:實現(xiàn)四個抽象方法
? ? ? ? ? ? ? ? ? ? ?getCount()得到數(shù)據(jù)源的總長度
? ? ? ? ? ? ? ? ? ? ?getItem(int position)得到下標對應(yīng)的Item
? ? ? ? ? ? ? ? ? ? ?getItemId(int position)得到下標對應(yīng)的Item的Id
? ? ? ? ? ? ? ? ? ? ?getView(int position,View convertView,ViewGrioup parent)
? ? ? ? ? step3:在getView方法中為每個Item配置布局和數(shù)據(jù)
(3)ListView的事件監(jiān)聽器
? ? ? ? ?①Item單擊響應(yīng)事件
? ? ? ? ? ? ?OnItemClickListener
? ? ? ? ?②Item長按響應(yīng)事件
? ? ? ? ? ? ?OnItemLongClickListener
? ? ? ? ?③ListView滾動事件
? ? ? ? ? ? ? listview.setOnScrollListener(new OnScroolListener()){
? ? ? ? ? ? ? ? ? ? ?//該方法監(jiān)聽listView滾動狀態(tài)的改變
? ? ? ? ? ? ? ? ? ? ?//AbsListView ----- listView
? ? ? ? ? ? ? ? ? ? ?//int scrollState----滾動的狀態(tài)
? ? ? ? ? ? ? ? ? ? ?//三種滾動狀態(tài)對應(yīng)三個狀態(tài)碼
? ? ? ? ? ? ? ? ? ? //OnScrollListener.SCROLL_STATE_TOUCH_SCROLL------1 listView正 ? ? ? ? ? ? ? ? ? ? ? 在滑動且手指還在屏幕上
? ? ? ? ? ? ? ? ? ? //OnScrollListener.SCROLL_STATE_FLING --------2? listView慣性滑動
? ? ? ? ? ? ? ? ? ? //OnScrollListener.SCROLL_STATE_IDLE? --------0? listView停止滑動
? ? ? ? ? ? ? ? ? ?public void onScrollStateChanged(AbsListView view,int scrollState){
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?//該方法監(jiān)聽listView滾動的方法
? ? ? ? ? ? ? ? ? ?//AbslistView view------listView
? ? ? ? ? ? ? ? ? //int firstVisibleItem ------當前屏幕最上方顯示的Item的下標
? ? ? ? ? ? ? ? ? //int visibleItemCount ------當前屏幕顯示Item的個數(shù),半個也算
? ? ? ? ? ? ? ? ? //int totalItemCount? -------當前所有Item的總數(shù)
? ? ? ? ? ? ? ? ? public void onScroll(AbsListView view,int firstVisibleItem,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int visibleItemCount,int totalItemCount){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //小技巧:判斷是否滑動到最底部
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Boolean islast = (firstVisible+visibleItemCount==totalItemCount);
? ? ? ? ? ? ? ? ? }
}
(4)ListView 的優(yōu)化
①屬性優(yōu)化:
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? ? ? ? ? ?如果是wrap_content,加載時每條Item會執(zhí)行多次來計算ListView的寬高
②重用convertView對象,將Item布局緩存起來從而復(fù)用
③定義ViewHolder類,減少findViewById的次數(shù)
參考代碼:
public View getView(int position, View convertView, ViewGroup parent) {
? ? ? ? ? ? ? ? ? ? ViewHolder holder;
? ? ? ? ? ? ? ? ? ? if (convertView == null) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?holder = new ViewHolder();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?convertView = View.inflate(context, R.layout.item_listview, null);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?holder.textViewName = (TextView) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? convertView.findViewById(R.id.name);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? holder.textViewDescription = (TextView) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?convertView.findViewById(R.id.description);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?convertView.setTag(holder);
? ? ? ? ? ? ? ? ? ? ? ?} else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? holder = (ViewHolder) convertView.getTag();
? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? holder.textViewName.setText(list.get(position).getName());
? ? ? ? ? ? ? ? ? ? ? holder.textViewDescription.setText(list.get(position).getDescription());
? ? ? ? ? ? ? ? ? ? ? return convertView;
}
(5)ListView加載網(wǎng)絡(luò)圖片,實現(xiàn)圖文混排
通常圖片地址在Json數(shù)據(jù)中或者XML文件中.(以json為例)
<1>通過網(wǎng)絡(luò)加載json數(shù)據(jù),然后解析封裝成類
<2>在ListView的Adapter中構(gòu)建Item時,
如果是文本內(nèi)容則直接設(shè)置,如果為圖片內(nèi)容則開啟異步任務(wù)去網(wǎng)絡(luò)中加載
<3>對加載好的圖片進行緩存,當?shù)诙涡枰故镜臅r候,直接在內(nèi)存中加載而不用訪問網(wǎng)絡(luò)
此處用Map來緩存(只是模擬),其他緩存方式后續(xù)更新
<4>由于convertView的復(fù)用,和異步任務(wù)形成的時間差,會造成圖片錯位現(xiàn)象
通過為ImageView打標簽可以解決圖片錯位的問題
代碼:??
Map<String,Bitmap> map = new HashMap<String,Bitmap>();
ViewHolder holder;
public View getView(int position, View convertView, ViewGroup parent) {
? ? ? ? ? ? if (convertView == null) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? holder = new ViewHolder();
? ? ? ? ? ? ? ? ? ? ? ? ? ? convertView = View.inflate(context, R.layout.item_listview, null);
? ? ? ? ? ? ? ? ? ? ? ? ? ? holder.imageView = (ImageView) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?convertView.findViewById(R.id.image);
? ? ? ? ? ? ? ? ? ? ? ? ? ? holder.textViewName = (TextView) convertView
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .findViewById(R.id.name);
? ? ? ? ? ? ? ? ? ? ? ? ? ? convertView.setTag(holder);
? ? ? ? ? ? ? ?} else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?holder = (ViewHolder) convertView.getTag();
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?holder.imageView.setImageResource(R.drawable.ic_launcher);//用于清空被 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 重用的holder中攜帶的圖片內(nèi)容
? ? ? ? ? ? ? ?String curImageUrl = list.get(position).getCoverUrl();
? ? ? ? ? ? ? ?holder.imageView.setTag(curImageUrl);//為ImageView打標簽,用此 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?imageView要顯示圖片的地址最為標簽
? ? ? ? ? ? ? ?if (!map.containsKey(curImageUrl)) {//判斷Map中是否存有該地址(圖片資源)
? ? ? ? ? ? ? ? ? ? ? ? ?//如果Map中沒有緩存,說明是第一次加載此圖片,需要從網(wǎng)絡(luò)獲取
? ? ? ? ? ? ? ? ? ? ? ? ?new ImageAsyncTask(new CallBack() {//開啟異步任務(wù)加載圖片
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?public void callBack(String path, Bitmap bitmap) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//通過回調(diào)方法返回加載圖片資源和其地址
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //將加載好的圖片資源和地址存入Map進行緩存
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? map.put(path, bitmap);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ImageView imageView = (ImageView) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? listView.findViewWithTag(path);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //通過標簽在ListView中找到對應(yīng)的imageView,并為其 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?設(shè)置圖片資源
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (imageView != null) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?imageView.setImageBitmap(bitmap);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }).execute(curImageUrl);
? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //如果Map中緩存的有需要的圖片,則直接拿過來使用
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?holder.imageView.setImageBitmap(map.get(curImageUrl));
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?holder.textViewName.setText(list.get(position).getName());
? ? ? ? ? ? ? ? return convertView;
}
class ViewHolder {
? ? ? ? ? ? ? ? ? ? ImageView imageView;
? ? ? ? ? ? ? ? ? ?TextView textViewName;
}